Search code examples
c#.netmacosxamarin.iosmonogame

Could not load file or assembly 'System.Drawing, Version=4.0.0.0


I installed Monogame, and when trying to run a very simple hello world style game I get this exception. I understand that there are several posts on stack overflow regarding this error, but am still puzzled as to how to fix this. Do I need to uninstall .Net and reinstall a different version? If so, how do I do that?

A System.IO.FileNotFoundException was thrown. Could not load file or assembly 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.

Here's a downloadable link to the Xamarin Project:

https://www.dropbox.com/s/q7quw26lg1etdts/MonoGameTester.zip


Solution

  • Such errors will occurs if you have reference to assemblies that do not ship with Xamarin.iOS. That's the case for System.Drawing.dll.

    In your case it's likely because your project has references to both monotouch.dll and MonoMac.dll and that's not gonna work.

    You need to build separate projects for each target, i.e. one for iOS (monotouch.dll) and one for OSX (MonoMac.dll).

    From each project you can share source code and/or assemblies (for shared logic). Both projects also need to include platform specific code and references.

    You end up with a lot of shared code (in source or assemblies) with a few platform specific bits of code.