Raygun Feature Request

Feature Request

Listen to unobserved exceptions in Tasks (TaskScheduler.UnobservedTaskException)

Current Status:

New

Votes:

1


Avatar

mattleibow

I am busy looking around at all the crash reporting and analytics libs and I do notice that Raygun does not appear to report the exceptions in Tasks.

public void Test()
{
    DoThrowDotNetTaskException();

    GC.Collect();
    GC.WaitForPendingFinalizers();
    GC.Collect();

    static void DoThrowDotNetTaskException()
    {
        var t = Task.Run(() =>
        {
            throw new Exception("From the Task thread.");
        });

        ((IAsyncResult)t).AsyncWaitHandle.WaitOne();

        t = null;
    }
}

See also:

https://learn.microsoft.com/dotnet/api/system.threading.tasks.taskscheduler.unobservedtaskexception


Avatar

mattleibow

Posted on
Jan 07 2024

I tried setting

options.RaygunSettings.CatchUnhandledExceptions = true;

But nothing is sent. I even subscribed to the

RaygunMauiClient.Current.SendingMessage

event but I did not get any events for the Task exceptions. The TaskScheduler.UnobservedTaskException event is raised, but Raygun does not appear to use it?

Avatar

mattleibow

Posted on
Jan 07 2024

Avatar

mattleibow

Posted on
Jan 07 2024

Avatar

Raygun

Deleted User

Posted on
Jan 10 2024

Hi Matthew,

You're absolutely right. We should be listening for UnobservedTaskException alongside other unhandled exceptions.

We noticed this late last year, and it's uncovered another issue when setting CatchUnhandledExceptions = true for any .NET5+ target. It doesn't actually register the callbacks, unless the application is specifically targeting netstandard2.0.

I note the comment on your PR, where you say it should probably exist in the Mindscape.Raygun4Net.NetCore.Common package, and I agree!

We have a branch in progress to fix the cross-platform unhandled exceptions. You can see this more specifically in this file here: https://github.com/MindscapeHQ/raygun4net/blob/fcec8d32b9329f4d87ad45aa9267f3ba17c341d7/Mindscape.Raygun4Net.NetCore.Common/GlobalExceptionHandler.cs

There is still some more work to be done here, but the end-goal is to effectively catch unhandled exceptions from as many target platforms as we can, and have them sent automatically to Raygun when that setting is enabled.

I'm expecting to release an updated version of the Raygun4Net.NetCore provider in the coming days, and I'll post here once that has been done.

Kind regards, Sean