Search code examples
c#xamarin.formsscreenshotxamarin.essentials

Xamarin.Essentials Screenshot not working on Android


I am following the documentation: https://learn.microsoft.com/en-us/xamarin/essentials/screenshot to take a screenshot and save it to MemoryStream then use it as the image source to "imagetest" (on a button click. Below is my code for the CaptureScreenshot() function, and I am getting the below error when executing the button click on an Android 10 device. I am running the latest versions of Xamarin.Essentials and Xamarin.Forms.

Function:

        private async void CaptureScreenshot(object sender, EventArgs e)
    {
        var screenshot = await Screenshot.CaptureAsync();
        var stream = await screenshot.OpenReadAsync();
        var array_image = ImageSource.FromStream(() => stream);
        imagetest.Source = array_image;
    }

Error:

"System.TypeLoadException Message=Could not load type of field 'Order_Form_V1.CustomArrayConfiguration+d__3:5__2' (6) due to: Could not resolve type with token 01000029 from typeref (expected class 'Xamarin.Essentials.ScreenshotResult' in assembly 'Xamarin.Essentials, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null') assembly:Xamarin.Essentials, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null type:Xamarin.Essentials.ScreenshotResult member:(null)"

I appreciate any input I can get.


Solution

  • You could have a try with cleaning the solution and removing all bin and obj folders, then rebulding it to check whether it works.

    Xamarin Forms: 5.0.0.1874

    Xamarin Essentials: 1.6.0

    Visual Studio : 16.8.4