CrimsonX
CrimsonX

Reputation: 9258

Does Xamarin's Android for Mono support same .NET libraries as Mono?

At a high level, my question is:

Is everything that is supported by Mono on a Linux platform supported by Android.Xamarin on an Android platform?

More information: I am investigating the possibility of porting a complex C# application which was targeting the .NET v3.5 framework onto an Android tablet, and want to confirm my understanding of what is supported in Mono vs what is supported on an Android device.

Mono's Compatibility list does a pretty great job of explaining what features are supported in the Mono architecture. As they so clearly state, mono supports:

Everything in .NET 4.0 except WPF, WWF, and with limited WCF.

However, understanding what is supported in Xamarin for Android is not as easy. I found this topic on Assemblies, which includes a description of the namespaces supported under System.dll

Silverlight, plus types from the following namespaces: [more listed]...

The silverlight reference mentions that System.Windows.Threading is under silverlight, but this doesnt seem to make sense if I simply create a new project.

Here's an example: if I open a new mono project and attempt to access System.Windows.Threading, I cannot access it unless I include a reference to WindowsBase.dll. Moreover, I can only successfully reference WindowsBase.dll from within an "Android Class Library" Project - if I attempt to create an "Android Application" Project and attempt to reference WindowsBase.dll I receive a cryptic compilation error, pasted below.

Error   2   Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'WindowsBase.dll'
   at Xamarin.Android.Tuner.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
   at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(List`1 assemblies, AssemblyDefinition assembly)
   at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(List`1 assemblies, AssemblyDefinition assembly)
   at Xamarin.Android.Tasks.ResolveAssemblies.Execute() C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets   720 2   AndoidCtmConnectionTester

So my follow up question is: Why would I get a compilation error when referencing a DLL from an Android Application project, but not an Android Class Library Project

Upvotes: 1

Views: 1852

Answers (1)

Michal Dobrodenka
Michal Dobrodenka

Reputation: 1144

System.Windows.Threading is considered as a part of WPF, so there no intention to make it work in Xamarin.Android.

If you want to reference .NET assembly directly, Xamarin.Android can load only few simple .NET assemblies (and with warning: "The referenced project is targeted to a different framework family (.NETFramework)" )

There is also a big chance that WindowsBase.dll is wrapping some win32 native methods, so it is impossible to run it under Android environment.

So the bad news is that you need to port your code to System.Threading classes.

Upvotes: 3

Related Questions