Skip to content
This repository was archived by the owner on May 15, 2024. It is now read-only.
This repository was archived by the owner on May 15, 2024. It is now read-only.

[Bug] Screenshot in UWP fails with exception (0x8001010E (RPC_E_WRONG_THREAD)) #1432

@zleao

Description

@zleao

Description

This issue is related to the functionality introduced in PR 744.
Using the screenshot API with the UWP sample, provided in the Xamarin Essentials repository, fails with a system exception, related to cross thread access (0x8001010E (RPC_E_WRONG_THREAD).
This only happened to me in UWP. I've tried the Android and iOS implementations and the result was successful.

Steps to Reproduce

  1. Run Xamarin Essentials sample app for UWP
  2. Go to Screenshot -> Take Screenshot

Expected Behavior

Screenshot taken and shown in the app

Actual Behavior

Exception is thrown:
System.Exception: 'The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))'

Basic Information

  • Version with issue: Main branch from current code repository (after tag 1.6.0-pre2)
  • Last known good version:
  • IDE: Visual Studio 2019 (16.7.5)
  • Platform Target Frameworks:
    • UWP: 16299
  • Affected Devices: Windows 10 Pro 2004

Screenshots

image

Aditional Info

I tracked down the exception source to the Screenshot UWP implementation line 39, when trying to access the bmp.PixelWidth. The problem is that the caller of the ScreenshotResult constructor is passing a object instance that was created in a different thread, since we have a ConfigureAwait(false) on line 24.
A quick solution could be setting it to ConfigureAwait(true) or removing the instruction all together.
Once this issue is confirmed as valid, I can make the PR myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions