I confess I'm new to Xamarin and cross-platform development, so apologies if this seems a trivial question, but I've been trying to get to the bottom of it for several evenings now.
I have a basic Xamarin Forms application, which runs in Windows 8.1, Windows UWP and Android. It uses SkiaSharp for some basic graphics (based on the Skia example).
It was running in all three platforms, but I had to remove and re-add the Xamarin packages to the project and I can't get SkiaSharp to run properly any more in Windows or Android. I get a BadImageFormatException:
Additional information: Could not load file or assembly 'SkiaSharp, Version=1.56.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' or one of its dependencies. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)
I get this exception in the x86, x64 and Any CPU configurations for the Windows 8.1 version, and from the Android version.
If I run it the UWP project, it works perfectly.
Relevant project structure:
- MyProj.XMForms (Portable) - PCL containing the core Xamarin.Forms App, MainPage with a StackLayout containing a Frame with a MyView, and MyView which contains a Grid with an SKCanvasView.
- MyProj.Windows (Windows 8.1) - wrapper - just contains an empty App and a MainPage which loads the MyProj.XMForms App.
- MyProj.UWP (Universal Windows) - wrapper - just contains an empty App and a MainPage which loads the MyProj.XMForms App.
- MyProj.Droid (Android) - wrapper - just contains a MainActivity which loads the MyProj.XMForms App.
All projects NuGet packages have Xamarin.Forms 2.3.3.180, SkiaSharp 1.56.0 and SkiaSharp.Views.Forms 1.56.0 . MyProj.Droid also has SkiaSharp.Views (none of the others will accept it).
I have discovered https://github.com/mono/SkiaSharp/issues/190 and added <ShouldIncludeNativeSkiaSharp>true</ShouldIncludeNativeSkiaSharp>
to the csproj without making any difference.
I have tried removing and re-adding the SkiSharp NuGet packages.
What am I missing?
Thanks,
Ian