Xamarin project failing to find SkiaSharp in Android or Windows

2

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

xamarin
skiasharp
asked on Stack Overflow Jan 30, 2017 by Ian Brockbank

2 Answers

3

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

answered on Stack Overflow Feb 6, 2017 by Matthew
0

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.

answered on Stack Overflow Feb 12, 2017 by Ian Brockbank

User contributions licensed under CC BY-SA 3.0