Bug 14254 - Linking error for assembly reference
Summary: Linking error for assembly reference
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools ()
Version: 6.4.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2013-08-26 21:11 UTC by Aaron Robertson-Hodder
Modified: 2014-01-22 21:21 UTC (History)
4 users (show)

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


Attachments
Xamarin solution for replication (284.86 KB, application/x-zip-compressed)
2013-08-26 21:11 UTC, Aaron Robertson-Hodder
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 FIXED

Description Aaron Robertson-Hodder 2013-08-26 21:11:15 UTC
Created attachment 4719 [details]
Xamarin solution for replication

I have an iOS universal project that references a library assembly that handles my web service calls. This assembly in turn references an external assembly that was build in Visual Studio against .net 4.0.

When I add this assembly to my library project and build it all is fine. However, if I then build the main iOS project I get the following error. Note that I also get this when I copy all the code from the Visual Studio project, create a brand new project in Xamarin Studio and build it and then reference that assembly from the library project.

The error is shown below and the full output is attached.

Performing main compilation...
/Library/Frameworks/Mono.framework/Versions/3.2.1/bin/mcs /noconfig "/r:/Developer/MonoTouch/usr/lib/mono/2.1/mscorlib.dll" -nostdlib "/out:/Users/aaron/Projects/TestCase/TestCase/bin/iPhone/Debug/TestCase.exe" "/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll" "/r:/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll" "/r:/Users/aaron/Projects/TestCase/References/MacroView.SharePoint.WebServices.Core.dll" "/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.Data.dll" "/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.Net.dll" "/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.Web.Services.dll" "/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.dll" "/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll" "/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll" /nologo /warn:4 /debug:full /optimize- /codepage:utf8 "/define:DEBUG;__MOBILE__;__IOS__"  /t:exe "/Users/aaron/Projects/TestCase/TestCase/Main.cs" "/Users/aaron/Projects/TestCase/TestCase/AppDelegate.cs" "/Users/aaron/Projects/TestCase/TestCase/TestCaseViewController.cs" "/Users/aaron/Projects/TestCase/TestCase/TestCaseViewController.designer.cs" "/Users/aaron/Projects/TestCase/TestCase/DMFListsService.cs" "/Users/aaron/Projects/TestCase/TestCase/DMFServiceProxy.cs" 
Compilation succeeded - 2 warning(s)

/Users/aaron/Projects/TestCase/TestCase/TestCaseViewController.cs(34,24): warning CS0672: Member `TestCase.TestCaseViewController.ShouldAutorotateToInterfaceOrientation(MonoTouch.UIKit.UIInterfaceOrientation)' overrides obsolete member `MonoTouch.UIKit.UIViewController.ShouldAutorotateToInterfaceOrientation(MonoTouch.UIKit.UIInterfaceOrientation)'. Add the Obsolete attribute to `TestCase.TestCaseViewController.ShouldAutorotateToInterfaceOrientation(MonoTouch.UIKit.UIInterfaceOrientation)'
/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll (Location of the symbol related to previous warning)
/Users/aaron/Projects/TestCase/TestCase/TestCaseViewController.cs(31,11): warning CS0219: The variable `data' is assigned but its value is never used



Compiling interface definitions
/Applications/Xcode.app/Contents/Developer/usr/bin/ibtool --errors --warnings --notices --output-format human-readable-text --compile "/Users/aaron/Projects/TestCase/TestCase/bin/iPhone/Debug/TestCase.app/TestCaseViewController.nib" "/Users/aaron/Projects/TestCase/TestCase/TestCaseViewController.xib" --sdk "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk"
2013-08-27 11:06:21.609 Interface Builder Cocoa Touch Tool[14196:f07] CFPreferences: user home directory at file://localhost/Users/aaron/Library/Application%20Support/iPhone%20Simulator/User/ is unavailable. User domains will be volatile.
Build complete -- 0 errors, 2 warnings

Compiling to native code
/Developer/MonoTouch/usr/bin/mtouch -sdkroot "/Applications/Xcode.app/Contents/Developer" --cache "/Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache" --nomanifest --nosign -dev "/Users/aaron/Projects/TestCase/TestCase/bin/iPhone/Debug/TestCase.app" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll" -r "/Users/aaron/Projects/TestCase/References/MacroView.SharePoint.WebServices.Core.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.Data.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.Net.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.Web.Services.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll" -debug -linksdkonly -sdk "6.1" -targetver "6.0" --abi=armv7 "-v" "-v" "-v" "/Users/aaron/Projects/TestCase/TestCase/bin/iPhone/Debug/TestCase.exe"
MonoTouch Business version 6.4.3.0 (0068990) using framework: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk
Copied /Users/aaron/Projects/TestCase/TestCase/bin/iPhone/Debug/TestCase.exe to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/TestCase.exe
Copied /Users/aaron/Projects/TestCase/TestCase/bin/iPhone/Debug/TestCase.exe.mdb to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/TestCase.exe.mdb
Copied /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/monotouch.dll
Copied /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll.mdb to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/monotouch.dll.mdb
Copied /Developer/MonoTouch/usr/lib/mono/2.1/mscorlib-runtime.dll to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/mscorlib.dll
Copied /Developer/MonoTouch/usr/lib/mono/2.1/mscorlib-runtime.dll.mdb to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/mscorlib.dll.mdb
Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/System.Core.dll
Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll.mdb to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/System.Core.dll.mdb
Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.dll to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/System.dll
Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.dll.mdb to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/System.dll.mdb
Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/System.Xml.dll
Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll.mdb to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/System.Xml.dll.mdb
Copied /Users/aaron/Projects/TestCase/References/MacroView.SharePoint.WebServices.Core.dll to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/MacroView.SharePoint.WebServices.Core.dll
Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.Web.Services.dll to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/System.Web.Services.dll
Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.Web.Services.dll.mdb to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/System.Web.Services.dll.mdb
Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.Data.dll to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/System.Data.dll
Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.Data.dll.mdb to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/System.Data.dll.mdb
Copied /Developer/MonoTouch/usr/lib/mono/2.1/Mono.Data.Tds.dll to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/Mono.Data.Tds.dll
Copied /Developer/MonoTouch/usr/lib/mono/2.1/Mono.Data.Tds.dll.mdb to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/Mono.Data.Tds.dll.mdb
Copied /Developer/MonoTouch/usr/lib/mono/2.1/Mono.Security.dll to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/Mono.Security.dll
Copied /Developer/MonoTouch/usr/lib/mono/2.1/Mono.Security.dll.mdb to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/Mono.Security.dll.mdb
Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.Transactions.dll to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/System.Transactions.dll
Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.Transactions.dll.mdb to /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/Link/System.Transactions.dll.mdb
Linking SDK only for assembly /Users/aaron/Projects/TestCase/TestCase/bin/iPhone/Debug/TestCase.exe into /Users/aaron/Projects/TestCase/TestCase/obj/iPhone/Debug/mtouch-cache/PreBuild
error MT2001: Could not link assemblies. Reason: Object reference not set to an instance of an object
	Object reference not set to an instance of an object
  at MonoTouch.Tuner.Linker.Process (MonoTouch.Tuner.LinkerOptions options, Mono.Linker.LinkContext& context, System.Collections.Generic.List`1& assemblies) [0x00000] in <filename unknown>:0 
  at MTouch.LinkAssemblies (System.String main, System.Collections.Generic.List`1& assemblies, System.String output_dir, Mono.Linker.LinkContext& link_context) [0x00000] in <filename unknown>:0 
  at MonoTouch.Application.ManagedLink () [0x00000] in <filename unknown>:0 
  at MonoTouch.Application.ProcessAssemblies () [0x00000] in <filename unknown>:0 
  at MonoTouch.Application.BuildApp () [0x00000] in <filename unknown>:0 
  at MonoTouch.Application.Build () [0x00000] in <filename unknown>:0 
  at MTouch.Main2 (System.String[] args) [0x00000] in <filename unknown>:0 
  at MTouch.Main (System.String[] args) [0x00000] in <filename unknown>:0
Comment 1 Sebastien Pouliot 2013-08-26 21:48:52 UTC
I was able to duplicate the issue with your test case. Huge thanks!
Comment 2 Sebastien Pouliot 2013-08-26 22:12:32 UTC
MacroView.SharePoint.WebServices.Core.dll has references to several members inside System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089`

The important bit is the version, i.e. 4.0.0.0, which is not 2.1.0.0 (as shipped with the Xamarin.iOS SDK).

The mobile profile, as shipped by Xamarin.iOS (and other products), do no support System.Configuration (the namespaces in several assemblies or the assembly itself). There's several reasons for this, including the fact that it makes linking almost impossible and, for iOS, it requires loading code dynamically (based on configuration files) which is something Apple does not allow (nor the AOT compiler which needs to compile *all* the code).

Still it should not report an NRE (that's a bug) but a meaningful error message, i.e.

error MT2002: Failed to resolve "System.Configuration.ApplicationSettingsBase" reference from "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
	Failed to resolve System.Configuration.ApplicationSettingsBase

The solution, on your side, is to rebuild MacroView.SharePoint.WebServices.Core.dll using the Xamarin.iOS assemblies shipped in the SDK (and that likely means some source customization to remove the dependency on System.Configuration).
Comment 3 Sebastien Pouliot 2013-08-26 22:14:13 UTC
The bug (NullReferenceException) is fixed in master bbf935cc5dab1582c89dbc3dadc19460c7277e3c
Comment 4 Aaron Robertson-Hodder 2013-08-26 22:27:15 UTC
That's fantastic, thanks! 

I am coming to realize that the I'm going to have to branch the original sources used in the windows app, modify the references to the Xamarin.iOS assemblies and re-build them. I guess cross-platform is not going to be as easy as I'd hoped. :(

Thanks again, your responsiveness is greatly appreciated!
Comment 5 Daniel Tavares 2014-01-22 21:04:50 UTC
I'm running into this same problem while using mtouch 7.0.5.2 (9c42159). When should we expect this fix to be released?

Thanks!
Comment 6 Sebastien Pouliot 2014-01-22 21:16:20 UTC
@Daniel, this fix is already released (i.e. part of 7.0.5).. You likely have a different, but similar, issue that result in a NRE. Please file a separate bug report and include a test case to reproduce it.
Comment 7 Daniel Tavares 2014-01-22 21:21:13 UTC
Indeed. I actually noticed that right after I posted my question. I tried the attached example and saw the expected output you mentioned earlier. The project I'm working on is fairly large and I may not be able to isolate the particular case. But I'll try. I'll post a new bug report with as much info as I can gather.

Thanks