The application I'm working with has recently started intermitting with hard crashes, which I cannot explain. To make it stranger, we have both AppDomain.CurrentDomain.UnhandledException, and TaskScheduler.UnobservedTaskExceptionto catch such problems.
Usually, when something goes wrong, these two failed ones work correctly, but we have certain circumstances when they do not catch unhandled exceptions. Even worse, the reason for this is NRE, which means we have nothing to do in terms of tracking what is happening.
My first thought was that perhaps the code that we have in the handled exception handlers may throw exceptions, so we have reduced the handling of exceptions here, but so far it has not made any difference. Magazines that we also could not shed light on.
It could be a bug with the webapi and / or owin bits that we use to host the application, and I'm going to try to run into dependencies to see if this helps, but I don't think it will make a difference.
Is there a way to catch unhandled exceptions that occur in a thread pool? Is there any kind of diagnostics we can get to find out more about where this happens?
I am at my end, any help would be greatly appreciated.
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Net.HttpListener.EndGetContext(IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.Owin.Host.HttpListener.OwinHttpListener.<ProcessRequestsAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__5(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
async void, Task.Run, . :
Task.Run(() => CleanUpAllExpiredErrors());
( ).