2012-07-10 70 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。