Search code examples
xamarinmvvmcrossportable-class-library

MvvmCross assembly referenced from Cirrious.MvvmCross.dll could not be loaded: System


I'm trying to set up a MvvmCross application project and run unit tests against it (namely the view models in it). I'm using Xamarin Studio on OS X (v. 4.0.4, latest at the time of writing).

The MvvmCross App is set up as a portable class library. The test assembly is set up as a plain Mono/.Net assembly (not PCL) referencing the NUnit framework.

When trying to execute the tests, they fail with a System.TypeLoadException.

I have run the tests with the Mono binding log on. Here's the output:

Mono: The following assembly referenced from /Users/jr/dev/rowinginmotion-cross/RowingInMotion.Mobile.BoatApp.Tests/bin/Debug/Cirrious.MvvmCross.dll could not be loaded: Assembly: System (assemblyref_index=3) Version: 2.0.5.0 Public Key: 7cec85d7bea7798e System error: Invalid argument

Mono: Failed to load assembly Cirrious.MvvmCross[0x559960]

Mono: Could not load file or assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies.

Is this test setup not supported=


Solution

  • This problem is linked to the fact that Xamarin and Mono don't yet properly support Portable Class Libraries - instead they compile and link against local fixed assemblies depending on what version of Mono (Xamarin.Android, Xamarin.iOS, etc) you have loaded - see http://slodge.blogspot.co.uk/2013/01/almost-portable-binaries.html for some more information.

    On Windows, you would be able to get around this problem using BindingRedirect functionality, but I haven't yet found any way to get around the problem using XBuild within Xamarin's environments (e.g. see my PCL and Mac issues on http://forums.xamarin.com/discussion/3733/playing-with-pcls)

    The only way I can see of currently loading this code in a full .Mac (.Net) project is to use the Xamarin recommended approach of file-linking - duplicating the project files and compiling the duplicate specifically against the appropriate target.

    Hopefully this is changing soon - as the official PCL support is due in alpha in the coming days and weeks.