Bug 34604

Summary: Compiler Crash in Mono.CSharp.CallEmitter.EmitPredefined with NRE
Product: [Mono] Compilers Reporter: Frank A. Krueger <fak>
Component: C#Assignee: Marek Safar <masafa>
Status: VERIFIED FIXED    
Severity: normal CC: arpitj, mono-bugs+monotouch, mono-bugs+mono, sebastien, shrutis
Priority: Normal    
Version: 4.0.0   
Target Milestone: 4.2.0 (C6)   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:

Description Frank A. Krueger 2015-10-06 15:02:44 UTC
The code:

			var activity = new NSUserActivity ("com.kruegersystems.new9.surfing") {
				UserInfo = {["someKey"] = new NSString ("someValue")},
			};

Crashes the compiler. I have no idea if the code is valid - converting to an NSDictionary.


	Target CoreCompile:
		Tool /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/smcs execution started with arguments: /noconfig /debug:full /debug+ /optimize- /out:obj/iPhone/Debug/New9.exe Main.cs AppDelegate.cs ViewController.cs ViewController.designer.cs ThreeDeeController.cs ThreeDeeController.designer.cs PressureView.cs PressureView.designer.cs ColorController.cs ColorController.designer.cs SearchController.cs SearchController.designer.cs /target:exe /define:"__UNIFIED__;__MOBILE__;__IOS__;DEBUG;ENABLE_TEST_CLOUD" /nostdlib /reference:/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/System.dll /reference:/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/System.Xml.dll /reference:/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Xamarin.iOS.dll /reference:/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/System.Core.dll /reference:/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/mscorlib.dll /warn:4
		
		Unhandled Exception:
		Mono.CSharp.InternalErrorException: SearchController.cs(20,61): New9.SearchController.<activity>m__0() ---> Mono.CSharp.InternalErrorException: SearchController.cs(20,67): ---> System.NullReferenceException: Object reference not set to an instance of an object
		   at Mono.CSharp.CallEmitter.EmitPredefined (Mono.CSharp.EmitContext ec, Mono.CSharp.MethodSpec method, Mono.CSharp.Arguments Arguments, Boolean statement, Nullable`1 loc) in <filename unknown>:line 0
		   at Mono.CSharp.CallEmitter.Emit (Mono.CSharp.EmitContext ec, Mono.CSharp.MethodSpec method, Mono.CSharp.Arguments Arguments, Location loc) in <filename unknown>:line 0
		   at Mono.CSharp.PropertyOrIndexerExpr`1[T].Emit (Mono.CSharp.EmitContext ec, Boolean leave_copy) in <filename unknown>:line 0
		   at Mono.CSharp.PropertyExpr.Emit (Mono.CSharp.EmitContext ec, Boolean leave_copy) in <filename unknown>:line 0
		   at Mono.CSharp.PropertyOrIndexerExpr`1[T].Emit (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.InstanceEmitter.EmitLoad (Mono.CSharp.EmitContext ec, Boolean boxInstance) in <filename unknown>:line 0
		   at Mono.CSharp.InstanceEmitter.Emit (Mono.CSharp.EmitContext ec, Boolean conditionalAccess) in <filename unknown>:line 0
		   at Mono.CSharp.CallEmitter.EmitPredefined (Mono.CSharp.EmitContext ec, Mono.CSharp.MethodSpec method, Mono.CSharp.Arguments Arguments, Boolean statement, Nullable`1 loc) in <filename unknown>:line 0
		   at Mono.CSharp.CallEmitter.Emit (Mono.CSharp.EmitContext ec, Mono.CSharp.MethodSpec method, Mono.CSharp.Arguments Arguments, Location loc) in <filename unknown>:line 0
		   at Mono.CSharp.IndexerExpr.EmitAssign (Mono.CSharp.EmitContext ec, Mono.CSharp.Expression source, Boolean leave_copy, Boolean isCompound) in <filename unknown>:line 0
		   at Mono.CSharp.Assign.Emit (Mono.CSharp.EmitContext ec, Boolean is_statement) in <filename unknown>:line 0
		   at Mono.CSharp.Assign.EmitStatement (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.ElementInitializer.EmitStatement (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.CollectionOrObjectInitializers.EmitStatement (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.CollectionOrObjectInitializers.Emit (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.ElementInitializer.EmitStatement (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.CollectionOrObjectInitializers.EmitStatement (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.CollectionOrObjectInitializers.Emit (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.NewInitialize.Emit (Mono.CSharp.EmitContext ec, IMemoryLocation target) in <filename unknown>:line 0
		   at Mono.CSharp.VariableReference.EmitAssign (Mono.CSharp.EmitContext ec, Mono.CSharp.Expression source, Boolean leave_copy, Boolean prepare_for_load) in <filename unknown>:line 0
		   at Mono.CSharp.Assign.Emit (Mono.CSharp.EmitContext ec, Boolean is_statement) in <filename unknown>:line 0
		   at Mono.CSharp.Assign.EmitStatement (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.BlockVariable.DoEmit (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.ParametersBlock.Emit (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.ToplevelBlock.Emit (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		  --- End of inner exception stack trace ---
		   at Mono.CSharp.ToplevelBlock.Emit (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.MethodData.Emit (Mono.CSharp.TypeDefinition parent) in <filename unknown>:line 0
		   at Mono.CSharp.MethodOrOperator.Emit () in <filename unknown>:line 0
		   at Mono.CSharp.Method.Emit () in <filename unknown>:line 0
		  --- End of inner exception stack trace ---
		   at Mono.CSharp.Method.Emit () in <filename unknown>:line 0
		   at Mono.CSharp.AnonymousExpression+AnonymousMethodMethod.Emit () in <filename unknown>:line 0
		   at Mono.CSharp.TypeDefinition.Emit () in <filename unknown>:line 0
		   at Mono.CSharp.ClassOrStruct.Emit () in <filename unknown>:line 0
		   at Mono.CSharp.Class.Emit () in <filename unknown>:line 0
		   at Mono.CSharp.TypeDefinition.EmitContainer () in <filename unknown>:line 0
		   at Mono.CSharp.TypeContainer.EmitContainer () in <filename unknown>:line 0
		   at Mono.CSharp.NamespaceContainer.EmitContainer () in <filename unknown>:line 0
		   at Mono.CSharp.TypeContainer.EmitContainer () in <filename unknown>:line 0
		   at Mono.CSharp.NamespaceContainer.EmitContainer () in <filename unknown>:line 0
		   at Mono.CSharp.TypeContainer.EmitContainer () in <filename unknown>:line 0
		   at Mono.CSharp.ModuleContainer.EmitContainer () in <filename unknown>:line 0
		   at Mono.CSharp.AssemblyDefinition.Emit () in <filename unknown>:line 0
		   at Mono.CSharp.AssemblyDefinitionStatic.Emit () in <filename unknown>:line 0
		   at Mono.CSharp.Driver.Compile () in <filename unknown>:line 0
		   at Mono.CSharp.Driver.Main (System.String[] args) in <filename unknown>:line 0
		[ERROR] FATAL UNHANDLED EXCEPTION: Mono.CSharp.InternalErrorException: SearchController.cs(20,61): New9.SearchController.<activity>m__0() ---> Mono.CSharp.InternalErrorException: SearchController.cs(20,67): ---> System.NullReferenceException: Object reference not set to an instance of an object
		   at Mono.CSharp.CallEmitter.EmitPredefined (Mono.CSharp.EmitContext ec, Mono.CSharp.MethodSpec method, Mono.CSharp.Arguments Arguments, Boolean statement, Nullable`1 loc) in <filename unknown>:line 0
		   at Mono.CSharp.CallEmitter.Emit (Mono.CSharp.EmitContext ec, Mono.CSharp.MethodSpec method, Mono.CSharp.Arguments Arguments, Location loc) in <filename unknown>:line 0
		   at Mono.CSharp.PropertyOrIndexerExpr`1[T].Emit (Mono.CSharp.EmitContext ec, Boolean leave_copy) in <filename unknown>:line 0
		   at Mono.CSharp.PropertyExpr.Emit (Mono.CSharp.EmitContext ec, Boolean leave_copy) in <filename unknown>:line 0
		   at Mono.CSharp.PropertyOrIndexerExpr`1[T].Emit (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.InstanceEmitter.EmitLoad (Mono.CSharp.EmitContext ec, Boolean boxInstance) in <filename unknown>:line 0
		   at Mono.CSharp.InstanceEmitter.Emit (Mono.CSharp.EmitContext ec, Boolean conditionalAccess) in <filename unknown>:line 0
		   at Mono.CSharp.CallEmitter.EmitPredefined (Mono.CSharp.EmitContext ec, Mono.CSharp.MethodSpec method, Mono.CSharp.Arguments Arguments, Boolean statement, Nullable`1 loc) in <filename unknown>:line 0
		   at Mono.CSharp.CallEmitter.Emit (Mono.CSharp.EmitContext ec, Mono.CSharp.MethodSpec method, Mono.CSharp.Arguments Arguments, Location loc) in <filename unknown>:line 0
		   at Mono.CSharp.IndexerExpr.EmitAssign (Mono.CSharp.EmitContext ec, Mono.CSharp.Expression source, Boolean leave_copy, Boolean isCompound) in <filename unknown>:line 0
		   at Mono.CSharp.Assign.Emit (Mono.CSharp.EmitContext ec, Boolean is_statement) in <filename unknown>:line 0
		   at Mono.CSharp.Assign.EmitStatement (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.ElementInitializer.EmitStatement (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.CollectionOrObjectInitializers.EmitStatement (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.CollectionOrObjectInitializers.Emit (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.ElementInitializer.EmitStatement (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.CollectionOrObjectInitializers.EmitStatement (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.CollectionOrObjectInitializers.Emit (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.NewInitialize.Emit (Mono.CSharp.EmitContext ec, IMemoryLocation target) in <filename unknown>:line 0
		   at Mono.CSharp.VariableReference.EmitAssign (Mono.CSharp.EmitContext ec, Mono.CSharp.Expression source, Boolean leave_copy, Boolean prepare_for_load) in <filename unknown>:line 0
		   at Mono.CSharp.Assign.Emit (Mono.CSharp.EmitContext ec, Boolean is_statement) in <filename unknown>:line 0
		   at Mono.CSharp.Assign.EmitStatement (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.BlockVariable.DoEmit (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.ParametersBlock.Emit (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.ToplevelBlock.Emit (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		  --- End of inner exception stack trace ---
		   at Mono.CSharp.ToplevelBlock.Emit (Mono.CSharp.EmitContext ec) in <filename unknown>:line 0
		   at Mono.CSharp.MethodData.Emit (Mono.CSharp.TypeDefinition parent) in <filename unknown>:line 0
		   at Mono.CSharp.MethodOrOperator.Emit () in <filename unknown>:line 0
		   at Mono.CSharp.Method.Emit () in <filename unknown>:line 0
		  --- End of inner exception stack trace ---
		   at Mono.CSharp.Method.Emit () in <filename unknown>:line 0
		   at Mono.CSharp.AnonymousExpression+AnonymousMethodMethod.Emit () in <filename unknown>:line 0
		   at Mono.CSharp.TypeDefinition.Emit () in <filename unknown>:line 0
		   at Mono.CSharp.ClassOrStruct.Emit () in <filename unknown>:line 0
		   at Mono.CSharp.Class.Emit () in <filename unknown>:line 0
		   at Mono.CSharp.TypeDefinition.EmitContainer () in <filename unknown>:line 0
		   at Mono.CSharp.TypeContainer.EmitContainer () in <filename unknown>:line 0
		   at Mono.CSharp.NamespaceContainer.EmitContainer () in <filename unknown>:line 0
		   at Mono.CSharp.TypeContainer.EmitContainer () in <filename unknown>:line 0
		   at Mono.CSharp.NamespaceContainer.EmitContainer () in <filename unknown>:line 0
		   at Mono.CSharp.TypeContainer.EmitContainer () in <filename unknown>:line 0
		   at Mono.CSharp.ModuleContainer.EmitContainer () in <filename unknown>:line 0
		   at Mono.CSharp.AssemblyDefinition.Emit () in <filename unknown>:line 0
		   at Mono.CSharp.AssemblyDefinitionStatic.Emit () in <filename unknown>:line 0
		   at Mono.CSharp.Driver.Compile () in <filename unknown>:line 0
		   at Mono.CSharp.Driver.Main (System.String[] args) in <filename unknown>:line 0
/Library/Frameworks/Mono.framework/Versions/4.2.1/lib/mono/4.5/Microsoft.CSharp.targets: error : Compiler crashed with code: 1.
	Task "Csc" execution -- FAILED


=== Xamarin Studio ===

Version 5.10 (build 811)
Installation UUID: e51e2705-c52a-4ae8-aa07-c481d6ab8a7a
Runtime:
	Mono 4.2.1 (explicit/804ddbc)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402010060

=== Xamarin.Profiler ===

Version: 0.22.0.0
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 7.0 (8223)
Build 7A218

=== Xamarin.iOS ===

Version: 9.2.0.84 (Enterprise Edition)
Hash: b5396c2
Branch: master
Build date: 2015-09-30 15:22:15-0400

=== Xamarin.Android ===

Version: 6.0.0.8 (Enterprise Edition)
Android SDK: /Users/fak/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)

SDK Tools Version: 23.0.5
SDK Platform Tools Version: 21
SDK Build Tools Version: 20

Java SDK: /usr
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

=== Xamarin Android Player ===

Version: 0.3.7
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 2.4.0.79 (Enterprise Edition)

=== Build Information ===

Release ID: 510000811
Git revision: 34cd31ea72536afab530c14d9220b286075e83cd
Build date: 2015-09-30 10:40:37-04
Xamarin addins: 8e6fccfc0c19a7e0b7b11be925f09751d827eb5c
Build lane: monodevelop-lion-cycle6

=== Operating System ===

Mac OS X 10.10.5
Darwin lepton.local 14.5.0 Darwin Kernel Version 14.5.0
    Wed Jul 29 02:26:53 PDT 2015
    root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64
Comment 1 Arpit Jha 2015-10-08 04:37:52 UTC
I have checked this and able to reproduce this issue with the help of bug description.

Steps I have followed to  reproduce this issue :

1.Create a xamarin.iOS app.
2.Implement following code in viewcontroller.cs 

           public override void ViewDidLoad ()
		{
			var activity = new NSUserActivity
				("com.kruegersystems.new9.surfing") {
				UserInfo = {["someKey"] = new NSString ("someValue")},
			};
			base.ViewDidLoad ();
			// Perform any additional setup after loading the view, typically from a nib.
		}

3.Build the application.
4.Getting build error.

Supplement Info:
Build Error: https://gist.github.com/Arpit360/160dd25185a0323dbf5c
Screencast:  http://www.screencast.com/t/NYdwK9TrF8

Environment Info:
=== Xamarin Studio ===

Version 5.10 (build 813)
Installation UUID: 3d25a767-a003-4a7d-9f5e-e57987cf6cf0
Runtime:
	Mono 4.2.1 (explicit/29c1622)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402010067

=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 7.0 (8227)
Build 7A220

=== Xamarin.iOS ===

Version: 9.2.0.85 (Trial Edition)
Hash: 7bcf0da
Branch: master
Build date: 2015-10-05 17:54:02-0400

=== Xamarin.Android ===

Version: 6.0.0.9 (Starter Edition)
Android SDK: /Users/mac360_xamarin/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)

SDK Tools Version: 24.3.4
SDK Platform Tools Version: 23
SDK Build Tools Version: 23

Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: 0.6.1
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Not Installed

=== Build Information ===

Release ID: 510000813
Git revision: 388e41428fb8f2910833c87fec0e7edaccd4f436
Build date: 2015-10-05 12:26:38-04
Xamarin addins: f21b254b56b36e417daee6da8b0300076f286ef1
Build lane: monodevelop-lion-cycle6

=== Operating System ===

Mac OS X 10.10.5
Darwin mac360-xamarins-Mac-mini.local 14.5.0 Darwin Kernel Version 14.5.0
    Wed Jul 29 02:26:53 PDT 2015
    root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64
Comment 2 Marek Safar 2015-10-08 09:11:24 UTC
Fixed in master/a4c91bbedfeb0bb5be95cdd52e5760b46a672493 and mono-4.2/d8b68fd5787b116201969176d88deb08924059d8
Comment 3 Shruti 2015-10-14 08:12:12 UTC
Hey Marek,

I have checked this issue with latest Master and C6 Mono. Application is getting build successfully with following code : 
var activity = new NSUserActivity
                ("com.kruegersystems.new9.surfing") {
                UserInfo = {["someKey"] = new NSString ("someValue")},
            };

But getting runtime exception when application is launched on simulator. I thinks I should file separate issue for this ? 

Please share your suggestions?


Screencast: http://www.screencast.com/t/ftJf6oTM
Master Environment Info: https://gist.github.com/Shruti360/4a803c19197d88fe337c
C6 Environment Info: https://gist.github.com/Shruti360/29d639ab309a727c7a57
Comment 4 Marek Safar 2015-10-14 08:42:03 UTC
Shruti,

Yes that's different issue
Comment 5 Shruti 2015-10-14 11:11:08 UTC
As per comment(3), I am able to build the application on Master and C6 builds. So I am closing this issue.

Filing new issue : https://bugzilla.xamarin.com/show_bug.cgi?id=34864 for the exception which I am getting at runtime.