2012-07-10 18 views
0

我有一个Asp.Net应用程序,我使用.NET 4.5 RC的新异步/等待范例。 我正在使用新的基于任务的异步http处理程序HttpTaskAsyncHandler来处理http请求。在我的代码中,我正在做一些I/O将文件传输到客户端。CurrentModuleContainer.Get中的零星NullPointerException异步处理时的Asp .Net代码

过一段时间我越来越具有以下堆栈跟踪NullPointerException

System.Web.dll中System.Web.HttpApplication.CurrentModuleContainer.get()+ 0X1E字节 的System.Web .DLL!System.Web.HttpApplication.PipelineStepManager.ResumeSteps(System.Exception的错误)+ 0xb7字节
System.Web.dll中!System.Web.HttpApplication.CallHandlerExecutionStep.OnAsyncHandlerCompletion(System.IAsyncResult AR)+ 0x1f3字节
的mscorlib .dll!System.Threading.Tasks.Task.Execute()+ 0x6e bytes mscorlib.dll!System.Threading .ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext,System.Threading.ContextCallback callback,object state,bool preserveSyncCtx)+ 0x285 bytes mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext,System。 Threading.ContextCallback回调,对象状态,布尔preserveSyncCtx)+ 0x9字节
mscorlib.dll中!System.Threading.Tasks.Task.ExecuteWithThreadLocal(REF System.Threading.Tasks.Task currentTaskSlot)+ 0x1c5字节
mscorlib.dll中!系统.Threading.Tasks.Task.ExecuteEntry(布尔bPreventDoubleExecution)+ 0XB0字节
mscorlib.dll中!System.Threading.ThreadPoolWorkQueue.Dispatch()+ 0x1ea字节
[原产于托管过渡]
[AppDomain的转型]
[原产于托管过渡]

这似乎发生后,我的代码已经返回的响应。

当发生这种情况时,下一个请求就不会被处理,而是在它恢复正常之后。

这种行为的原因是什么?我查看了CurrentModuleContainer.Get方法的源代码,看起来唯一可以抛出空指针异常的是Http上下文。

+0

没有代码就无能为力,尽管NullReferenceException意味着你试图使用一个空的变量。 – 2012-07-15 17:44:33

+0

你有没有想过这个?我看到同样的事情。看到这里:http://stackoverflow.com/questions/33698395/unobservedtaskexception-where-did-the-task-come-from – dmarlow 2015-12-02 16:30:46

回答

0

异常可能来自许多不同的原因,但可以猜测您正尝试访问您的处理程序中的当前HttpContext,在异步结束函数期间可能为null。