MAUI: Don't rely on DeviceDisplay/DeviceInformation
Closed this issue · 1 comments
daltzctr commented
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
- Create a new MAUI project
SentrySdk.CaptureMessage()
from a separate thread- Observe crashes
Expected Result
Does not crash
Actual Result
Crashes.
This is because DeviceDisplay & DeviceInformation are
- Not meant to be polled, which means the device reporting logic is dangerous
- 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.
jamescrosswell commented
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?