Skip to content

MAUI .NET 9 System.ObjectDisposedException crash #4241

@claytonone

Description

@claytonone

Package

Sentry.Maui

.NET Flavor

.NET

.NET Version

9.0.5

OS

Android

OS Version

No response

Development Environment

Visual Studio v17.x

SDK Version

5.9.0

Self-Hosted Sentry Version

No response

Workload Versions

Maui 9.0.70
dotnet 9

UseSentry or SentrySdk.Init call

.UseSentry(options =>
{
    options.Dsn = "";
    options.TracesSampleRate = 1;
    options.DisableUnobservedTaskExceptionCapture();
    options.SetBeforeSend((e, hint) =>
    {
        try
        {
            if (e?.SentryExceptions?.FirstOrDefault()?.Type == "App Hanging")
            {
                return null;
            }
        }
        catch
        {
        }

        return e;
    });
});

Steps to Reproduce

  1. Run a maui app in release mode that uses navigation page rather than shell
  2. Navigate between pages that have text entry's

Expected Result

The app doesn't crash

Actual Result

The app occasionally crashes with an object disposed exception when navigating between pages in the app. Removing sentry from app stops it crashing. These crashes did not happen when our app was built with .net 8.

The Maui control mentioned in the first line varies but the below stack trace is the most prolific. My guess is that Sentry is doing something when the page is unloaded.

System.ObjectDisposedException: ObjectDisposed_Generic
ObjectDisposed_ObjectName_Name, Microsoft.Maui.Platform.MauiTextView
  ?, in void JniPeerMembers.AssertSelf(IJavaPeerable)
  ?, in void JniInstanceMethods.InvokeVirtualVoidMethod(string, IJavaPeerable, JniArgumentValue*)
  ?, in void View.RemoveOnAttachStateChangeListener(IOnAttachStateChangeListener)
  ?, in void View.remove_ViewDetachedFromWindow(EventHandler<ViewDetachedFromWindowEventArgs>)+(IOnAttachStateChangeListener __v) => { } [0]
  ?, in void EventHelper.RemoveEventHandler<IOnAttachStateChangeListener, IOnAttachStateChangeListenerImplementor>(ref WeakReference, Func<IOnAttachStateChangeListenerImplementor, bool>, Action<IOnAttachStateChangeListener>, Action<IOnAttachStateChangeListenerImplementor>)
  ?, in void View.remove_ViewDetachedFromWindow(EventHandler<ViewDetachedFromWindowEventArgs>)
  ?, in IDisposable ViewExtensions.OnUnloaded(View view, Action action)+() => { } [1]
  ?, in void ActionDisposable.Dispose()
  ?, in IDisposable ViewExtensions.OnUnloaded(View view, Action action)+() => { } [3]
  ?, in void RunnableImplementor.Run()
  ?, in void IRunnableInvoker.n_Run(IntPtr jnienv, IntPtr native__this)
  ?, in void JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V callback, IntPtr jnienv, IntPtr klazz)

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETPull requests that update .net codeBugSomething isn't workingFramework: MAUI

    Projects

    Status

    Done

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions