Bug 4533 - How to use window .net .dll in to mono touch
Summary: How to use window .net .dll in to mono touch
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools ()
Version: 5.2
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-04-19 14:55 UTC by Kartik
Modified: 2012-04-23 09:53 UTC (History)
3 users (show)

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

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:

Description Kartik 2012-04-19 14:55:26 UTC

This is not bug.. but i need help please..

I am using Monodevelop to develop iPad app. We already have .net 4.0 compiled .dll which i need to use in mono develop project. 

I was working with simulator and it was working fine. We just buy mono touch and try to deploy to device, but it's not compiling and give me error

Error MT2001: Could not link assemblies (MT2001)

I search online and i found that i could not use .net compiled .dll directly to mono touch project while deploy to device, we need to compile using mono touch. 

I created class library Monodevelop project, add .net compiled .dll release mono touch class library .dll. I checked release folder but it's create all .dll reference. So now i took those files and added to iPad mono touch project and add to reference but still same problem.

I am not sure how i can compile .net precompiled .dll using mono touch. 

Please guide me. I am almost ready to deploy to device and this issue stop me to do that.
Comment 1 Mikayla Hutchinson [MSFT] 2012-04-23 08:46:52 UTC
If it works with the simulator but the linker fails when building for device, that sounds like a linker bug.

To compile a class library for MonoTouch, create a MonoTouch Library project, and add your sources to that (you can add them as "links" instead of copying the files). Then, reference that project from your MonoTouch app.
Comment 2 Sebastien Pouliot 2012-04-23 09:40:25 UTC
This is not a linker bug, you'll get a similar error, later, if you disable the linker (on devices).

What happens is that assemblies compiled against .NET 4.0 includes references to types and methods that are not available in the assemblies provided by MonoTouch. You can see them (or at least the first one) if you add "-v -v -v" to the "additional mtouch arguments" in your project options.

That "can" work on the iOS simulator uses the JIT. The Just In Time part means that the missing symbols won't cause issue until the code paths, that uses them, are executed. If they are never executed then you'll never see the (runtime) exceptions.

However for devices we need to AOT (compile ahead of time) the assemblies. That moves the runtime error (for the JIT) to become compile-time error. IOW such assemblies won't work on devices as the missing types/methods will _always_ be found (and be un-compilable).

The fact that it fails at the linker stage is that, like the AOT compiler, the linker process the whole application and finds the missing references before the AOT compiler.

The only solution is the one Michael provided. Re-compile your assembly (from source code) inside a MonoTouch Library project, i.e. against the assemblies shipped with MonoTouch. This is the only way you can be sure they won't reference types/methods that are not available.

note: a future version of MonoTouch (once Mono 2.12 is released) will be based on .NET 4.0 - however the current version is still based on the Silverlight profile (2.1) with some 4.0 additions.
Comment 3 Kartik 2012-04-23 09:53:39 UTC
Ok, I will follow those instruction..

Thanks for your comments and time.