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

痞子三分冷 提交于 2019-12-19 08:14:49

问题


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

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

My Android target version is :

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

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


回答1:


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.




回答2:


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.)



来源:https://stackoverflow.com/questions/10551652/prexisiting-dlls-net-4-framework-issue-with-mono-for-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!