getsentry/sentry-dotnet

MAUI: Don't rely on DeviceDisplay/DeviceInformation

Closed this issue · 1 comments

Package

Sentry.Maui

.NET Flavor

.NET

.NET Version

8.0.60

OS

Any (not platform specific)

SDK Version

4.7.0

Self-Hosted Sentry Version

No response

Steps to Reproduce

  1. Create a new MAUI project
  2. SentrySdk.CaptureMessage() from a separate thread
  3. Observe crashes

Expected Result

Does not crash

Actual Result

Crashes.

This is because DeviceDisplay & DeviceInformation are

  1. Not meant to be polled, which means the device reporting logic is dangerous
  2. Not thread safe on certain platforms (iOS, MacCatalyst, Windows).

Additionally, DeviceDisplay and DeviceInformation are not guarenteed to be valid in certain situations, such as startup, shutdown, or even in some cases in multi-window applications.

I'm not able to reproduce this on iOS 17.2 or macCatalyst, using the following sample code:

public partial class MainPage : ContentPage
{
    private int _count = 0;

    public MainPage()
    {
        InitializeComponent();
    }

    private void OnCounterClicked(object sender, EventArgs e)
    {
        _count++;
        var thread = new Thread(() =>
        {
            SentrySdk.CaptureMessage($"Click count: {_count}");
        });
        thread.Start();
        CounterBtn.Text = $"Click count: {_count}";
        thread.Join();
    }
}

@daltzctr are you able to provide a simple project and instructions on how to reproduce this reliably?