0

I've been following the examples for using SkiaSharp with Xamarin Forms, particularly the section on using bitmaps. I'm doing this in Microsoft Visual Studio 2017 version 15.9.11. I'm only targeting Android currently.

This page https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/graphics/skiasharp/basics/bitmaps has a section on Loading a Bitmap Resource, where the bitmap is an embedded image resource in the project.

So, we add the image and make it type 'embedded resource' added as an embedded resource

and then run the example code to simply display the image on the canvas.

string resourceID = "SkiaTest.Media.monkey.png";
Assembly assembly = GetType().GetTypeInfo().Assembly;

using (Stream stream = assembly.GetManifestResourceStream(resourceID))
{
    resourceBitmap = SKBitmap.Decode(stream);
}

All pretty simple, and it works fine if I run the code on my phone if it is connected via USB in the standard way (a Sony Z5) so the second in the list here, not the Player:

drop down list of players in VS

Here it is working via USB:

working via USB

But if I try and use Xamarin Live Player (the first in the list above) then it crashes on this line:

using (Stream stream = assembly.GetManifestResourceStream(resourceID))

enter image description here

Note that the app runs fine in Live Player if I don't try and load the bitmap, it's only that line that triggers the crash, and only in Live Player.

So I wonder if anyone has any ideas what could be causing Live Player to fail over this issue? Is the resource not being copied to the phone? Does Live Player just not support this type of activity?

Ralpharama
  • 441
  • 4
  • 20
  • Xamarin Live player is still in preview(If I am correct) has bugs and is still under development and there are a lot of things which do not work with it this could be one of them just check this for better understanding, possibly there could be a way to solve this [here](https://learn.microsoft.com/en-us/xamarin/tools/live-player/troubleshooting) but i wouldn't rely on live player for now – FreakyAli Apr 08 '19 at 14:10
  • Thanks @g-hakim. Ah! "Embedded resources are not supported (ie. embedding images or other resources in a PCL)" DOH! Well, that's that then! – Ralpharama Apr 08 '19 at 14:13
  • Want me to add this as an answer? – FreakyAli Apr 08 '19 at 14:15
  • 1
    Sure, I've selected you as answering correctly. Thanks. – Ralpharama Apr 08 '19 at 14:26

1 Answers1

1

The reason you are facing this issue is that Embedded Resources are not yet supported by Xamarin Live player which is causing this exception.

More details can be found in the Troubleshooting Xamarin Live Player document.

FreakyAli
  • 13,349
  • 3
  • 23
  • 63