I have a .NET 4.0 web project and use Microsoft.Bcl.Async to support async/await feature.
I've noticed that in production environment IIS worker process continiously crashes due to NullReferenceException which is thrown at System.Runtime.CompilerServices.AsyncServices.<ThrowAsync>b__1()
.
It seems that the exception is thrown some place else in my code and is rethrown at AsyncServices.ThrowAsync()
method. Unfortunately any exception details (including original stack trace) are lost so I don't know where the exception has been thrown originally.
Moreover, I've tried to catch this exception using AppDomain.CurrentDomain.UnhandledException and TaskScheduler.UnobservedTaskException events but these event are never fired.
There are all error details I have (from EventLog):
Exception: System.NullReferenceException
Message: Object reference not set to an instance of an object.
StackTrace: at System.Runtime.CompilerServices.AsyncServices.<ThrowAsync>b__1(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()
There are no obvious places in my code that may throw this exception and process crashes without any output.
How do I debug this? Are there any ways to find the source of this exception?