Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prexisiting dlls (.NET 4 framework) issue with mono for android

I am creating a fresh Mono for android application using http://xamarin.com/monoforandroid enter image description here

I selected Mono for Android Application using Visual C# option.

My Android target version is : enter image description here

I went to references of the project and tried adding my pre existing dlls (made in .NET 4 Framework) and I got this error:

enter image description here

The strange stuff is there is no option to change the .NET Framework from project properties. Can you tell me what I am missing?

like image 528
Rocky Singh Avatar asked May 11 '12 12:05

Rocky Singh


2 Answers

The problem here is that you're trying to reference a .NET 4 DLL from a project that isn't .NET 4. Mono for Android uses its own profile for .NET, which is very similar to that of Silverlight (but not exactly the same). While it's possible that adding a DLL compiled for a different profile will work, it's very risky as you will probably run into problems at runtime where your app will crash, due to something being missing from the Mono for Android profile.

The best answer right now is to create a Mono for Android class library, link in the appropriate files from the library you want to use, and reference that. This will give you compile-time checking that you're not using anything unsupported by the Mono for Android profile, and help keep you more sane in the long run. I have an old blog post up here that talks about how to link files across projects.

That said, in this case you're in luck because someone else has already done that last part for you! Check out this fork of Json.NET which provides versions for MonoTouch and Mono for Android.

like image 163
Greg Shackles Avatar answered Sep 25 '22 06:09

Greg Shackles


The strange stuff is there is no option to change the .NET Framework from project properties. Can you tell me what I am missing?

It's not particularly strange - that dialog box was written by Microsoft, with its own project types in mind. It sounds like Mono for Android doesn't have the same options available.

I strongly suspect you'll just have to use a version of JSON.NET targeting .NET 3.5.

(Having said that, Mono for Android claims to support "dynamic language features" which sounds like it should be targeting .NET 4. Odd. I suspect the fix is the same though.)

like image 32
Jon Skeet Avatar answered Sep 21 '22 06:09

Jon Skeet