In our WPF application, we do register an event handler for unobserved task exception:
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
with the following method:
private static void OnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs exceptionEventArgs)
{
_logger.Error(exceptionEventArgs.Exception, Properties.Resources.TaskExceptionsWereNotObserved);
exceptionEventArgs.SetObserved();
}
I do get the full stack trace:
System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (The I/O operation has been aborted because of either a thread exit or an application request.)
---> System.Net.Sockets.SocketException (995): The I/O operation has been aborted because of either a thread exit or an application request.
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Net.Sockets.SocketReceiveFromResult>.GetResult(Int16 token)
at System.Threading.Tasks.ValueTask`1.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
--- End of inner exception stack trace ---
But nothing seems to be in our code.
My question:
Is there a way to add more debug information to know where this was triggered? Because I'm not even sure the exception happens in our code or in an external library.