I'm trying to load an image by a given base 64 string.
I have the following XAML Image:
<Image x:Name="CustomImage"></Image>
And I have this method on the class page, whose is called after InitializeComponent() in the constructor:
public void LoadImage(string imageString)
{
CustomImage.Source = ImageSource.FromStream(() =>
{
return imageString.StringToStream();
});
}
The extension method called:
public static Stream StringToStream(this string image)
{
var imageBytes = Convert.FromBase64String(image);
using (var ms = new MemoryStream())
{
ms.Write(imageBytes, 0, imageBytes.Length);
return ms;
}
}
No exception is thrown by the method, but an unhandled exception is thrown after the code is executed.
What I am doing wrong? I can't catch the exception, because is thrown outside my code.