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?
You cannot use Microsoft.Bcl.Async
on IIS; it's entirely unsupported. Sorry.
To summarize from the referenced blog post: the behavior of async / await is undefined in ASP.NET unless the aspnet:UseTaskFriendlySynchronizationContext
app setting is set to true
or the httpRuntime.targetFramework
attribute is set to 4.5
.
And those options don't affect the ASP.NET 4 runtime.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With