6

我有一个 .NET 4.0 Web 项目并使用 Microsoft.Bcl.Async 来支持 async/await 功能。我注意到在生产环境中 IIS 工作进程由于在System.Runtime.CompilerServices.AsyncServices.<ThrowAsync>b__1(). 似乎异常是在我的代码中的其他地方抛出的,并在AsyncServices.ThrowAsync()方法中重新抛出。不幸的是,任何异常详细信息(包括原始堆栈跟踪)都丢失了,所以我不知道异常最初是在哪里引发的。此外,我尝试使用 AppDomain.CurrentDomain.UnhandledException 和 TaskScheduler.UnobservedTaskException 事件来捕获此异常,但这些事件从未被触发。

我有所有错误详细信息(来自 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()

我的代码中没有明显的地方可能会引发此异常并在没有任何输出的情况下处理崩溃。

我该如何调试?有没有办法找到这个异常的来源?

4

1 回答 1

3

不能Microsoft.Bcl.Async在 IIS 上使用;它完全不受支持。对不起。

从引用的博客文章中总结:async / await 的行为在 ASP.NET 中是未定义的,除非aspnet:UseTaskFriendlySynchronizationContext应用程序设置设置为truehttpRuntime.targetFramework属性设置为4.5.

这些选项不会影响 ASP.NET 4 运行时。

于 2013-10-16T14:55:39.683 回答