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:
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
If you look at the exception message, there is this line:
Reference assemblies should not be loaded for execution.
That means you haven't installed the SkiaSharp NuGets into the app projects. Make sure all the apps have the SkiaSharp
, SkiaSharp.Views
and SkiaSharp.Views.Forms
NuGets installed. The core project only needs the SkiaSharp
and SkiaSharp.Views.Forms
NuGets.
Also, Windows 8.x is not currently supported due to a limitation in Skia: https://github.com/mono/SkiaSharp/issues/20
Okay, I've managed to get Android working by taking the Android project from the SkiaSharp FormsSample and replacing the call to
LoadApplication(new SkiaSharpSample.FormsSample.Platform.App());
with
LoadApplication(new MyPortable.XamarinForms.App());
My original project definitely included all the same NuGets as this one, and I haven't yet identified they key difference which meant that this one worked and mine didn't, but at least I now have a solution which works in both Android and UWP.
User contributions licensed under CC BY-SA 3.0