【问题标题】:sporadic NullPointerException in CurrentModuleContainer.Get Asp .Net code when doing async handling执行异步处理时 CurrentModuleContainer.Get Asp .Net 代码中的零星 NullPointerException
【发布时间】:2012-07-16 05:20:02
【问题描述】:

我有一个 Asp .Net 应用程序,我正在使用新的 async/await 范例和 .net 4.5 RC。 我正在使用新的基于任务的异步 http 处理程序 HttpTaskAsyncHandler 来处理 http 请求。在我的代码中,我正在做一些 I/O 将文件流式传输到客户端。

偶尔我会收到一个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 字节 mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback 回调, 对象状态, bool preserveSyncCtx) + 0x285 字节 mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback 回调, 对象状态, bool preserveSyncCtx) + 0x9 bytes
mscorlib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot) + 0x1c5 字节
mscorlib.dll!System.Threading.Tasks.Task.ExecuteEntry(bool bPreventDoubleExecution) + 0xb0 字节
mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() + 0x1ea 字节
[本机到托管转换]
[Appdomain 转换]
[本机到托管转换]

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

当这种情况发生时,下一个请求永远不会被处理,但之后的请求会恢复正常。

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

【问题讨论】:

  • 没有代码就无法帮助,尽管 NullReferenceException 意味着您尝试使用为 null 的变量。
  • 你有没有想过这个问题?我看到同样的事情。见这里:stackoverflow.com/questions/33698395/…

标签: asp.net asynchronous .net-4.5 async-await asp.net-4.5


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2013-07-17
    • 2017-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-13
    • 2015-08-08
    • 2016-05-19
    相关资源
    最近更新 更多