Bug 44521 - MTOUCH: error MT2001: Could not link assemblies. Reason: Value cannot be null.
Summary: MTOUCH: error MT2001: Could not link assemblies. Reason: Value cannot be null.
Status: RESOLVED DUPLICATE of bug 44122
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 10.0 (iOS10)
Hardware: PC Mac OS
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-09-20 12:39 UTC by Yaroslav
Modified: 2017-03-07 20:22 UTC (History)
8 users (show)

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


Attachments
Claudio Redi Xamarin Studio About (1.67 KB, text/plain)
2016-09-20 20:27 UTC, Claudio Redi
Details
Claudio Redi Build Output (407.03 KB, text/plain)
2016-09-20 20:28 UTC, Claudio Redi
Details
advancedOutputXamarin (6.23 KB, text/plain)
2016-09-21 06:58 UTC, Yaroslav
Details
Log build error Link Assemblies (6.58 MB, text/plain)
2016-09-22 17:49 UTC, Rafael Nicolett
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:
RESOLVED DUPLICATE of bug 44122

Description Yaroslav 2016-09-20 12:39:13 UTC
Linking /Users/<user>/<project dir>.iOS/bin/iPhone/Debug//PDFExample.exe into /Users/<user>/<project dir>.iOS/obj/iPhone/Debug/build-ipad4.1-10.0/mtouch-cache/PreBuild using mode 'SDKOnly'
MTOUCH: error MT2001: Could not link assemblies. Reason: Value cannot be null.
		Parameter name: dst
			Value cannot be null.
		Parameter name: dst
	Task "MTouch" execution -- FAILED
	Done building target "_CompileToNative" in project "/Users/<user>/<prject dir>.iOS/<Project Name>.iOS.csproj".-- FAILED
	
Done building project "/Users/<user>/<prject dir>.iOS/<Project Name>.iOS.csproj".-- FAILED

Build FAILED.

Warnings:

/Users/<user>/<prject dir>.iOS/<Project Name>.iOS.csproj (Build) ->
/Library/Frameworks/Mono.framework/Versions/4.6.0/lib/mono/xbuild/14.0/bin/Microsoft.CSharp.targets (CoreCompile target) ->

<...>

Errors:

/Users/<user>/<prject dir>.iOS/<Project Name>.iOS.csproj (Build) ->
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets (_CompileToNative target) ->

	MTOUCH: error MT2001: Could not link assemblies. Reason: Value cannot be null.

	 9 Warning(s)
	 1 Error(s)



-----------
Xamarin Studio Business
Version 6.1 (build 5441)
Installation UUID: 5f49ba21-463b-410c-86b6-67dcb26953ae
Runtime:
	Mono 4.6.0 (mono-4.6.0-branch/746756c) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 406000245

NuGet
Version: 3.4.3.0

Xamarin.Profiler
Not Installed

Xamarin.Android
Not Installed

Xamarin Android Player
Not Installed

Apple Developer Tools
Xcode 8.0 (11246)
Build 8A218a

Xamarin.iOS
Version: 10.0.0.6 (Xamarin Business)
Hash: 6c3fee4
Branch: xcode8
Build date: 2016-09-09 13:01:32-0400

Xamarin.Mac
Not Installed

Build Information
Release ID: 601005441
Git revision: 68292d1ab289911c815ddc715dd7cc29a9752f9f
Build date: 2016-09-09 04:43:23-04
Xamarin addins: ed25d008672663eeb9db55f1ccecb3c24d2fd3b2
Build lane: monodevelop-lion-cycle8

Operating System
Mac OS X 10.11.6
Darwin yfedorov-mac.local 15.6.0 Darwin Kernel Version 15.6.0
    Mon Aug 29 20:21:34 PDT 2016
    root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64



And I found looks the same issue report on Xamarin forum https://forums.xamarin.com/discussion/78119/error-when-compiling-with-link-framework-sdk-only
Comment 1 Yaroslav 2016-09-20 12:57:53 UTC
Sorry, I forgot to say that I'm trying to build the project in Debug mode for iPad Air, with iOS 10.0 (14A5346a). In iOS project options I have set option Link Frameworks SDKs Only.

In Release mode, I'm alse have problem. but it looks a little bit different.

	 <...>
		Copied /Library/Frameworks/Xamarin.iOS.framework/Versions/10.0.0.6/lib/mono/2.1/Facades/System.Reflection.dll to /Users/<user>/<project dir>.iOS/obj/iPhone/Release/mtouch-cache/32/Link/System.Reflection.dll
		Copied /Library/Frameworks/Xamarin.iOS.framework/Versions/10.0.0.6/lib/mono/2.1/Facades/System.Linq.Expressions.dll to /Users/<user>/<project dir>.iOS/obj/iPhone/Release/mtouch-cache/32/Link/System.Linq.Expressions.dll
		Copied /Library/Frameworks/Xamarin.iOS.framework/Versions/10.0.0.6/lib/mono/2.1/Facades/System.Globalization.dll to /Users/<user>/<project dir>.iOS/obj/iPhone/Release/mtouch-cache/32/Link/System.Globalization.dll
		Copied /Library/Frameworks/Xamarin.iOS.framework/Versions/10.0.0.6/lib/mono/2.1/Facades/System.Diagnostics.Tools.dll to /Users/<user>/<project dir>.iOS/obj/iPhone/Release/mtouch-cache/32/Link/System.Diagnostics.Tools.dll
		Copied /Library/Frameworks/Xamarin.iOS.framework/Versions/10.0.0.6/lib/mono/2.1/Facades/System.Reflection.Extensions.dll to /Users/<user>/<project dir>.iOS/obj/iPhone/Release/mtouch-cache/32/Link/System.Reflection.Extensions.dll
MTOUCH: error MT1010: Could not load the assembly '/Users/<user>/<project dir>.iOS/obj/iPhone/Release/mtouch-cache/32/Link/<My library name>.iOS.dll': Error while loading assemblies: /Users/<user>/<project dir>.iOS/obj/iPhone/Release/mtouch-cache/32/Link/<My library name>.iOS.dll
			Error while loading assemblies: /Users/<user>/<project dir>.iOS/obj/iPhone/Release/mtouch-cache/32/Link/<My library name>.iOS.dll
			Buffer cannot be null.
		Parameter name: buffer
	Task "MTouch" execution -- FAILED
	Done building target "_CompileToNative" in project "/Users/<user>/<Project dir>.iOS/<Project Name>.iOS.csproj".-- FAILED
	
Done building project "/Users/<user>/<project dir>.iOS/<Project Name>.iOS.csproj".-- FAILED

Build FAILED.

Warnings:
<...>

Errors:

/Users/<user>/<Project dir>.iOS/<Project Name>.iOS.csproj (Build) ->
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets (_CompileToNative target) ->

	MTOUCH: error MT1010: Could not load the assembly '/Users/<user>/<project dir>.iOS/obj/iPhone/Release/mtouch-cache/32/Link/<My library name>.iOS.dll': Error while loading assemblies: /Users/<user>/<Project dir>.iOS/obj/iPhone/Release/mtouch-cache/32/Link/<My library name>.iOS.dll

	 11 Warning(s)
	 1 Error(s)

Time Elapsed 00:00:18.5160840
Comment 2 Claudio Redi 2016-09-20 13:37:15 UTC
I have a similar problem. Created a thread on xamarin forum https://forums.xamarin.com/discussion/78119/error-when-compiling-with-link-framework-sdk-only?

There you'll find part of the stacktrace
Comment 3 Alex Soto [MSFT] 2016-09-20 18:57:01 UTC
Hello Yaroslav, Claudio

Please include your full build logs, crash reports (if any), 
test case (to reproduce) and all version informations.

The easiest way to get exact version information is to use the 
"Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" 
button and copy/paste the version informations (you can use the 
"Copy Information" button).



@Jeff/@Vincent does this rings any bell?

MTOUCH: error MT2001: Could not link assemblies. Reason: Value cannot be null.
		Parameter name: dst
			Value cannot be null.
		Parameter name: dat

Also https://bugzilla.xamarin.com/show_bug.cgi?id=44516 looks related but not sure
Comment 4 Alex Soto [MSFT] 2016-09-20 19:49:00 UTC
One thing I forgot to mention Claudio please add

-v -v -v -v

To "Additional mtouch arguments" inside your project settings > Build > iOS build

So we get a more detailed build logs
Comment 5 Claudio Redi 2016-09-20 20:27:41 UTC
Created attachment 17620 [details]
Claudio Redi Xamarin Studio About
Comment 6 Claudio Redi 2016-09-20 20:28:25 UTC
Created attachment 17621 [details]
Claudio Redi Build Output
Comment 7 Yaroslav 2016-09-21 06:58:01 UTC
Created attachment 17630 [details]
advancedOutputXamarin
Comment 8 Rafael Nicolett 2016-09-22 15:33:07 UTC
Same problem here!!!
Comment 9 Yaroslav 2016-09-22 16:54:05 UTC
I think this bug is related https://bugzilla.xamarin.com/show_bug.cgi?id=44122
Comment 10 Rafael Nicolett 2016-09-22 17:49:05 UTC
Created attachment 17688 [details]
Log build error Link Assemblies

This is my log with arguments -v -v -v -v
Comment 11 Sebastien Pouliot 2016-09-23 15:46:38 UTC
PR (master) https://github.com/xamarin/xamarin-macios/pull/887

A workaround is to edit the mtouch script

> /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch


and change `mono` to `mono64`

*** This bug has been marked as a duplicate of bug 44122 ***
Comment 12 Rafael Nicolett 2016-09-23 18:53:30 UTC
Don't work for me. Same problem after change script.
Comment 13 Sebastien Pouliot 2016-09-23 19:18:17 UTC
@Rafael your problem might be different. Please open a different bug report, including with a test case, so we can duplicate the issue. Thanks!
Comment 14 Rafael Nicolett 2016-09-23 19:31:02 UTC
This open 

https://bugzilla.xamarin.com/show_bug.cgi?id=44701
Comment 15 Claudio Redi 2016-09-23 21:00:29 UTC
In my case the workaround didn't work. Do I have to restart the machine or something else beside changing the script?
Comment 16 Sebastien Pouliot 2016-09-23 21:06:30 UTC
@Claudio your stack trace looks similar to @Rafael, but not @Yaroslav - which is the one (of two) I had a test cases for, both fixed by the same switch to 64 bits.

IOW both you and @Rafael are likely hitting a different issue and I'll need a test case to reproduce it.

Since you're the original reporter of the bug I'm re-opening this one.
Comment 17 Claudio Redi 2016-09-23 21:34:41 UTC
I'm not sure if I'll be able to provide a test case since need to isolate the problem and I imagine this is not happening on a simple test project. 

A  task that you may queue on your side in the meantime is a better handling for null on offending method, more information about what's causing the null could be the key.
Comment 18 Yaroslav 2016-09-26 10:19:27 UTC
@Sebastien Pouliot
Changed `mono` to `mono64`and my problem is gone. Thank you.
Comment 19 Sebastien Pouliot 2016-09-27 20:42:26 UTC
Thanks for confirming!

*** This bug has been marked as a duplicate of bug 44122 ***
Comment 20 jon.hunt 2016-12-12 15:56:47 UTC
Changing the 'mono' to 'mono64' in the above script did not resolve the issue. My /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch script already had mono64 in it.

Any other ideas? I have XCode 8.1 and compiling with iOS SDK 10.1 and getting this crash. I really need to be able to build my app!

1>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(700,3): error : Could not link assemblies. Reason: Object reference not set to an instance of an object
1>  --- inner exception
1>  System.NullReferenceException: Object reference not set to an instance of an object
1>    at MonoTouch.Tuner.OptimizeGeneratedCodeSubStep.ProcessIsDirectBinding (Mono.Cecil.MethodDefinition caller, Mono.Cecil.Cil.Instruction ins) [0x00020] in <b7bf8a35f2f54e83ba243d3bc07010fc>:0 
1>    at MonoTouch.Tuner.OptimizeGeneratedCodeSubStep.ProcessCalls (Mono.Cecil.MethodDefinition caller, System.Int32 i) [0x00308] in <b7bf8a35f2f54e83ba243d3bc07010fc>:0 
1>    at MonoTouch.Tuner.OptimizeGeneratedCodeSubStep.ProcessMethod (Mono.Cecil.MethodDefinition method) [0x00045] in <b7bf8a35f2f54e83ba243d3bc07010fc>:0 
1>    at Xamarin.Linker.CoreOptimizeGeneratedCode.ProcessMethods (System.Collections.Generic.IEnumerable`1[T] c, System.Boolean extensions) [0x0003a] in <b7bf8a35f2f54e83ba243d3bc07010fc>:0 
1>    at Xamarin.Linker.CoreOptimizeGeneratedCode.ProcessType (Mono.Cecil.TypeDefinition type) [0x0005a] in <b7bf8a35f2f54e83ba243d3bc07010fc>:0 
1>    at MonoTouch.Tuner.OptimizeGeneratedCodeSubStep.ProcessType (Mono.Cecil.TypeDefinition type) [0x00018] in <b7bf8a35f2f54e83ba243d3bc07010fc>:0 
1>    at Mono.Tuner.SubStepDispatcher.DispatchType (Mono.Cecil.TypeDefinition type) [0x00032] in <b7bf8a35f2f54e83ba243d3bc07010fc>:0 
1>    at Mono.Tuner.SubStepDispatcher.BrowseTypes (System.Collections.ICollection types) [0x00018] in <b7bf8a35f2f54e83ba243d3bc07010fc>:0 
1>    at Mono.Tuner.SubStepDispatcher.BrowseAssemblies (System.Collections.Generic.IEnumerable`1[T] assemblies) [0x0004d] in <b7bf8a35f2f54e83ba243d3bc07010fc>:0 
1>    at Mono.Tuner.SubStepDispatcher.Process (Mono.Linker.LinkContext context) [0x0000e] in <b7bf8a35f2f54e83ba243d3bc07010fc>:0 
1>    at Mono.Linker.Pipeline.Process (Mono.Linker.LinkContext context) [0x00023] in <b7bf8a35f2f54e83ba243d3bc07010fc>:0 
1>    at MonoTouch.Tuner.Linker.Process (MonoTouch.Tuner.LinkerOptions options, MonoTouch.Tuner.MonoTouchLinkContext& context, System.Collections.Generic.List`1[System.String]& assemblies) [0x000a5] in <b7bf8a35f2f54e83ba243d3bc07010fc>:0 
1>  ---
1>    at MonoTouch.Tuner.Linker.Process (MonoTouch.Tuner.LinkerOptions options, MonoTouch.Tuner.MonoTouchLinkContext& context, System.Collections.Generic.List`1[System.String]& assemblies) [0x0014e] in <b7bf8a35f2f54e83ba243d3bc07010fc>:0 
1>    at Xamarin.Bundler.Target.LinkAssemblies (System.String main, System.Collections.Generic.List`1[System.String]& assemblies, System.String output_dir, MonoTouch.Tuner.MonoTouchLinkContext& link_context) [0x00236] in <b7bf8a35f2f54e83ba243d3bc07010fc>:0 
1>    at Xamarin.Bundler.Target.ManagedLink () [0x003a6] in <b7bf8a35f2f54e83ba243d3bc07010fc>:0 
1>    at Xamarin.Bundler.Target.ProcessAssemblies () [0x000e4] in <b7bf8a35f2f54e83ba243d3bc07010fc>:0 
1>    at Xamarin.Bundler.Application.BuildApp () [0x0002f] in <b7bf8a35f2f54e83ba243d3bc07010fc>:0 
1>    at Xamarin.Bundler.Application.Build () [0x00052] in <b7bf8a35f2f54e83ba243d3bc07010fc>:0 
1>    at Xamarin.Bundler.Driver.Main2 (System.String[] args) [0x01c6c] in <b7bf8a35f2f54e83ba243d3bc07010fc>:0 
1>    at Xamarin.Bundler.Driver.Main (System.String[] args) [0x0000c] in <b7bf8a35f2f54e83ba243d3bc07010fc>:0 
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========
Comment 21 Sebastien Pouliot 2016-12-12 16:07:28 UTC
@Jon, if it does not work then your issue is different.

Please open a new bug report, include all versions information* and a test case so we can reproduce the issue. Thanks.

* The easiest way to get exact version information is to use the "Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" button and copy/paste the version informations (you can use the "Copy Information" button).
Comment 22 jon.hunt 2016-12-12 16:08:52 UTC
The stack trace is exactly the same as this bug. I can open a new bug but most likely will be marked as a duplicate of this one. I will create a new bug.
Comment 23 James Hancock 2017-01-30 16:43:34 UTC
This is still an issue with the latest version supplied in VS.net for Mac and VS.net 2017 RC.
Comment 24 Sergio Chaves 2017-03-07 12:43:46 UTC
In our case, we removed the "[XamlCompilation(XamlCompilationOptions.Compile)]" class diretive and was able to compile. We are working in Visual Studio 2015, targeting .NET Framework 4.5 and generation IPA to SDK 10.2, using the "Link SDK assemblies only" link behavior, our build configuration is Ad-Hoc and supporting both ARMv7s and ARM64 architectures. Hope this help.
Comment 25 James Hancock 2017-03-07 19:59:49 UTC
FYI, this bug still happens in today's release of VS.net for Mac.
Comment 26 Sebastien Pouliot 2017-03-07 20:07:22 UTC
Like mentioned in comment #21 an error code (like MT2001) and a bug (like this one) are two different things. IOW this bug is closed and verified - but it's not the only reason for MT2001 and that error is not always a bug in mtouch.

If you have a different issue, with the same error code, then please open a new bug report, include all versions information* and a test case so we can reproduce the issue. Thanks.

* The easiest way to get exact version information is to use the "Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" button and copy/paste the version informations (you can use the "Copy Information" button).
Comment 27 James Hancock 2017-03-07 20:08:34 UTC
I'm the one that reported this in the first place and I'm telling you that it IS NOT FIXED.

This should be reopened and dealt with and fixed properly. You have all of the information above that you've requested. Let me know if there is more you need.
Comment 28 Sebastien Pouliot 2017-03-07 20:22:22 UTC
This bug was filed by Yaroslav (Fedorov.mail@gmail.com) and confirmed as fixed in comment #18.