Skip to content

[Android] SentrySdk.CaptureException deadlocks Android UI when AttachScreenshot is enabled with .NET MAUI 10.0.90 #5494

Closed

Description

@MichaelShapiro

Package

Sentry.Maui

.NET Flavor

.NET

.NET Version

10.0.303

OS

Android

OS Version

No response

Development Environment

Visual Studio v18.x

Other Error Monitoring Solution

No

Other Error Monitoring Solution Name

No response

SDK Version

6.9.0

Self-Hosted Sentry Version

No response

UseSentry or SentrySdk.Init call

            .UseSentry(options => 
            {
                options.Dsn = "https://[ENTER YOUR DSN]";
                options.Debug = true;
                options.AttachScreenshot = true;    
            });

Steps to Reproduce

Calling SentrySdk.CaptureException or throwing exception from the Android UI thread freezes the application indefinitely when:

options.AttachScreenshot = true;

The call never returns and normal exception-handling flow cannot continue.
Disabling screenshot attachment completely avoids the problem:

options.AttachScreenshot = false;

Minimal reproduction

Repo Android Deadlock

Configure Sentry in a .NET MAUI 10.0.90 application:

builder.UseSentry(options =>
{
    options.Dsn = "...";
    options.Debug = true;
    options.AttachScreenshot = true;
});

Capture a handled exception from the UI thread, such as from a button command:

private void CaptureTestException()
{
    try
    {
        throw new InvalidOperationException("Sentry screenshot test");
    }
    catch (Exception ex)
    {
        SentryId eventId = SentrySdk.CaptureException(ex);

        // This line is never reached on Android.
        Debug.WriteLine(eventId);
    }
}

Regression checks
The same Android behavior was reproduced with both Sentry.Maui 6.5.0 and 6.8.0 while using MAUI 10.0.90.
The application previously submitted Android events with screenshots successfully when using earlier MAUI 10.0.x releases. The behavioral change appears to begin with MAUI 10.0.90.
Downgrading only Sentry does not resolve the problem.

Suspected root cause
Sentry’s MAUI screenshot attachment still treats Android screenshot capture as synchronously completed.
In Sentry.Maui 6.9.0, ScreenshotAttachmentContent contains:

var screen = Screenshot.Default
    .CaptureAsync()
    .ConfigureAwait(false)
    .GetAwaiter()
    .GetResult();

return screen
    .OpenReadAsync(ScreenshotFormat.Jpeg)
    .ConfigureAwait(false)
    .GetAwaiter()
    .GetResult();

Source Sentry ScreenshotAttachment.cs

The accompanying comment says Android’s MAUI implementation returns Task.FromResult. That assumption is no longer valid in MAUI 10.0.90.
MAUI PR #35384 changed Android screenshot capture to use PixelCopy.Request: PR #35384

The PixelCopy completion callback is posted through a handler associated with Looper.MainLooper.
This produces the following deadlock when CaptureException runs on the UI thread:

  1. Sentry calls Screenshot.CaptureAsync().
  2. Sentry synchronously blocks using GetAwaiter().GetResult().
  3. MAUI waits for the PixelCopy callback.
  4. The callback is scheduled on the Android main looper.
  5. The main thread cannot process the callback because it is blocked inside Sentry.
  6. CaptureException never returns.

Suggested correction
Please update the Sentry.Maui screenshot attachment implementation so it does not synchronously block the Android UI thread while waiting for MAUI’s asynchronous PixelCopy screenshot capture.
The existing source comment claiming Android screenshot capture returns Task.FromResult should also be updated because it no longer reflects MAUI 10.0.90 behavior.

Expected Result

Expected result
SentrySdk.CaptureException should return without blocking the Android UI thread, and the exception should be queued with its screenshot attachment.

Actual Result

On Android:
SentrySdk.CaptureException never returns.
The UI thread remains blocked.
The application appears completely frozen.
No subsequent error handling or navigation executes.
On iOS, CaptureException returns successfully and the event includes a screenshot.

Activity

  1. added
    Bug
    .NET
    on Aug 17, 2026
  2. linear-code commented on Aug 17, 2026

    @linear-code
  3. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Aug 17, 2026
  4. jamescrosswell commented on Aug 19, 2026

    @jamescrosswell
    Collaborator

    @MichaelShapiro thanks for the report.

    Confirmed and reproduced.

    The primary cause is that MAUI's RenderUsingPixelCopyAsync has changed (in dotnet/maui@c2b81f9) from this:

    public Task<IScreenshotResult> CaptureAsync(View view)
    {
        var bitmap = Render(view);                          // synchronous canvas draw
        return Task.FromResult<IScreenshotResult>(result);  // already-completed Task
    }

    To this:

    PixelCopy.Request(window, rect, bitmap, listener, new Handler(Looper.MainLooper!));
    try
    {
        return await tcs.Task.ConfigureAwait(true);
    }

    Sentry blocks on it:

    var screen = Screenshot.Default.CaptureAsync().ConfigureAwait(false).GetAwaiter().GetResult();

    The main thread is inside GetResult(), so Android's Looper.MainLooper never drains... so OnPixelCopyFinished never runs = deadlock.

    Emergency workaround

    For the time being you either have to disable screenshot capture or, otherwise, the best you can do is:

    options.SetBeforeScreenshotCapture((e, h) => !MainThread.IsMainThread);

    That basically drops any attempt to capture screenshots on the MainUI thread... which will still be most of them. It will leave intact any screenshot capture by the sentry-java SDK though - so you might get a few.

    Brainstorming

    1. One option is to duplicate a bunch of the logic from MAUI's screenshot capture logic and use a different handler when calling PixelCopy.Request, so blocking the caller is safe.
    2. This is arguably a MAUI bug. Hardcoding Looper.MainLooper makes CaptureAsync impossible to await synchronously from the UI thread for any consumer.
  5. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Aug 19, 2026
  6. MichaelShapiro commented on Aug 19, 2026

    @MichaelShapiro
    Author

    @jamescrosswell I ended up doing this:

    ...
            return Task.Run<string?>(() =>
            {
                SentryId sentryEventID = SentrySdk.CaptureException(ex);
    
                return sentryEventID.ToString();
            });
    
    

    and I had to convert all call sites to async calling of course. Maybe there is a better, but I wanted to preserve screen capture. I'm surprised no one reported it yet -seems like a problem :(

  7. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Aug 19, 2026
  8. jamescrosswell commented on Aug 19, 2026

    @jamescrosswell
    Collaborator

    I ended up doing this:

    Ah, that's a good solution. You might want to couple it with my suggestion since Unhandled exceptions would still deadlock.

    There's also a chance that the screenshot you get doesn't exactly represent the screen at the time of the exception now, since the capture happens async... but overall, I think you preserve more information with this solution 👍🏻

    I'm surprised no one reported it yet -seems like a problem :(

    MAUI 10.0.90 is pretty recent... I've created a tracking issue in the MAUI repo:

    The only way I can think of working around it in Sentry involves duplicating (and maintaining) a bunch of the MAUI code in our repo - so would definitely rather get this fixed upstream, if possible.

  9. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Aug 19, 2026
  10. jamescrosswell commented on Aug 26, 2026

    @jamescrosswell
    Collaborator

    Looks like this has been addressed in .NET:

    Presumably that fix will be included in the 10.0.12 release. I don't think there's anything for us to do in this repo then @MichaelShapiro.

  11. MichaelShapiro commented on Aug 27, 2026

    @MichaelShapiro
    Author

    thank you!

  12. dartasen commented on Sep 8, 2026

    @dartasen

    Fix seems to be part of the SR10.1 release (although not mentionned in the changelog) : dotnet/maui@10.0.100...10.0.101

    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETAttachmentsBug

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions