Xamarin Live Player crashes when loading a bitmap, but it runs fine via USB connection

时间:2019-04-08 14:02:08

标签: xamarin xamarin.forms skiasharp xamarin-live-player

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://docs.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?

1 个答案:

答案 0 :(得分:0)

您面临此问题的原因是,导致此异常的Xamarin Live播放器尚不支持嵌入式资源。

更多详细信息可以在this old post文档中找到。