Bug 21541 - error MT2001: Could not link assemblies. Reason: Object reference not set to an instance of an object
Summary: error MT2001: Could not link assemblies. Reason: Object reference not set to ...
Status: VERIFIED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 7.2.6
Hardware: PC Mac OS
: High major
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-07-23 06:36 UTC by Rolf Bjarne Kvinge [MSFT]
Modified: 2014-07-23 15:36 UTC (History)
6 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Main.cs (455 bytes, application/octet-stream)
2014-07-23 06:43 UTC, Rolf Bjarne Kvinge [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Rolf Bjarne Kvinge [MSFT] 2014-07-23 06:36:40 UTC
This occurs when enabling linking for all assemblies the attached project:

error MT2001: Could not link assemblies. Reason: Object reference not set to an instance of an object
--- inner exception
System.NullReferenceException: Object reference not set to an instance of an object
  at MonoTouch.Tuner.OptimizeGeneratedCodeSubStep.ProcessCalls (Mono.Cecil.MethodDefinition caller, Int32 i) [0x00000] in <filename unknown>:0 
  at MonoTouch.Tuner.OptimizeGeneratedCodeSubStep.ProcessMethod (Mono.Cecil.MethodDefinition method) [0x00000] in <filename unknown>:0 
  at Xamarin.Linker.CoreOptimizeGeneratedCode.ProcessMethods (IEnumerable`1 c) [0x00000] in <filename unknown>:0 
  at Xamarin.Linker.CoreOptimizeGeneratedCode.ProcessType (Mono.Cecil.TypeDefinition type) [0x00000] in <filename unknown>:0 
  at MonoTouch.Tuner.OptimizeGeneratedCodeSubStep.ProcessType (Mono.Cecil.TypeDefinition type) [0x00000] in <filename unknown>:0 
  at Mono.Tuner.SubStepDispatcher.DispatchType (Mono.Cecil.TypeDefinition type) [0x00000] in <filename unknown>:0 
  at Mono.Tuner.SubStepDispatcher.BrowseTypes (ICollection types) [0x00000] in <filename unknown>:0 
  at Mono.Tuner.SubStepDispatcher.BrowseAssemblies (IEnumerable`1 assemblies) [0x00000] in <filename unknown>:0 
  at Mono.Tuner.SubStepDispatcher.Process (Mono.Linker.LinkContext context) [0x00000] in <filename unknown>:0 
  at Mono.Linker.Pipeline.Process (Mono.Linker.LinkContext context) [0x00000] in <filename unknown>:0 
  at MonoTouch.Tuner.Linker.Process (MonoTouch.Tuner.LinkerOptions options, MonoTouch.Tuner.MonoTouchLinkContext& context, System.Collections.Generic.List`1& assemblies) [0x00000] in <filename unknown>:0 

Note: the MT2001 error is fairly generic, and captures many possible failure scenarios. This bug report is only for when the stack trace matches exactly as well.
Comment 1 Rolf Bjarne Kvinge [MSFT] 2014-07-23 06:36:51 UTC
This is a regression in 7.2.6.
Comment 2 Rolf Bjarne Kvinge [MSFT] 2014-07-23 06:43:07 UTC
Created attachment 7474 [details]
Main.cs

To repro:

mkdir tmp.app
/Developer/MonoTouch/usr/bin/smcs Main.cs -out:tmp.app/Main.exe -r:/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll
/Developer/MonoTouch/usr/bin/mtouch tmp.app/Main.exe
Comment 3 Rolf Bjarne Kvinge [MSFT] 2014-07-23 06:51:11 UTC
Fixed.

monotouch/master: bbd1dc5ef4eaeaec6c5c0596643760fd55d7d161

Sebastien, can you have a second look and see if it's done correctly?
Comment 5 Mohit Kheterpal 2014-07-23 12:33:39 UTC
I have checked this issue with X.iOS 7.2.6.26 and run the command given in comment 2,

Output with X.iOS 7.2.6.25 : https://gist.github.com/Mohit-Kheterpal/85327a9a8282fc8a3368

Output  with X.iOS 7.2.6.26 : https://gist.github.com/Mohit-Kheterpal/31a5ed2fc72bb689c966

Please have a look.
Comment 6 Rolf Bjarne Kvinge [MSFT] 2014-07-23 12:52:11 UTC
@Mohit, note that unit tests were added with the fix in comment #3

In any case if you add "-sdk 7.1" to the last command the test code builds fine:

/Developer/MonoTouch/usr/bin/mtouch tmp.app/Main.exe -sdk 7.1
Comment 7 Mohit Kheterpal 2014-07-23 13:00:29 UTC
I have tried command mention in comment 6 and now I am getting following result :

Last login: Wed Jul 23 21:49:41 on ttys000
360Logicas-Mac-mini:~ 360logicaxamarinmacmini$ /Developer/MonoTouch/usr/bin/smcs Main.cs -out:tmp.app/Main.exe -r:/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll
360Logicas-Mac-mini:~ 360logicaxamarinmacmini$ /Developer/MonoTouch/usr/bin/mtouch tmp.app/Main.exe -sdk 7.1
Xamarin.iOS: USING STAGING SERVER FOR ACTIVATION
Xamarin.iOS 7.2.6 Business Edition using framework: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk
warning MT0042: No reference to either monotouch.dll or Xamarin.iOS.dll was found. A reference to monotouch.dll will be added.
warning MT0030: The executable name (Main.exe) and the app name (.) are different, this may prevent crash logs from getting symbolicated properly.
. built successfully.
360Logicas-Mac-mini:~ 360logicaxamarinmacmini$