【问题标题】:Why is ASP.NET throwing so many exceptions?为什么 ASP.NET 会抛出这么多异常?
【发布时间】:2011-03-30 14:31:23
【问题描述】:

碰巧我看了一点 Visual Studio 的调试输出。我可以看到成百上千的各种异常被抛出。我检查了另一个基于 ASP.NET 的解决方案,它显示出相同的行为。为什么会抛出所有这些异常?我不敢相信这对整体性能有好处,是吗? 请看下面的摘录。它是 appr 的输出。 30 秒冲浪。大多数是 HttpExceptions,但也有 FormatExceptions 和 ArgumentOutOfRangeExceptions。这些都没有真正影响使用。没有什么崩溃。有没有人有解释,因为这似乎是“正常的”?

A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
'w3wp.exe' (Managed): Loaded 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\a402e511\e6aaa0de\App_Web_vdj_eurz.dll', Symbols loaded.
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.InvalidCastException' occurred in mscorlib.dll
A first chance exception of type 'System.InvalidCastException' occurred in mscorlib.dll
A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll

【问题讨论】:

  • 如果你重建网站,它可以工作吗?
  • 没有。我的意思是,一切正常。只是想知道这些例外是什么意思。
  • 我看到你接受了一个答案。我还是很好奇:这种行为到底是正常的,还是你的代码造成的?
  • 是的,是我的代码造成的。这是关于你最终在大型项目中遇到的所有那些小小的尝试捕捉块。其中一些我可以通过简单地添加 NULL 检查而不是 try-catch 来修复。其他人正在按预期工作,例如尝试使用反射重新连接事件处理程序时。
  • 这个故事的寓意是摆脱那些 try/catch 块,这样您就可以快速找出代码有什么问题并修复它。

标签: asp.net iis


【解决方案1】:

我不确定到底是什么原因造成的,但我知道您可以如何找到(更好,对吧?:))。

在 Visual Studio 中:

  • 点击“调试”菜单
  • 点击“例外...”
  • 检查“公共语言运行时异常”中的“抛出”

这将使 Visual Studio 在出现任何异常时停止调试器,以便您检查实际发生的情况。 (不影响生产代码,只在VS中停止)

作为旁注,您可能希望实现 automatic exception emailing 或类似的东西,以从生产站点获取更多信息。

请注意,您可能无法立即捕获 VS 中的所有异常(第一次异常有时可能有点难以捉摸)。如果你想更硬核,你也可以使用 Visual Studio 调试器debug the .Net Framework。您的目标应该是查看完整的异常 + 堆栈跟踪,这在大多数情况下会告诉您所有问题所在。

一个好的做法是消除异常(查找原因并修复),不要隐藏或忽略它们。

编辑

first chance exceptions”是很可能被 try-catch 捕获的异常,这一点也毫无价值。当满足特定条件时,.Net 中的一些内部函数会抛出异常,这是 Visual Studio/调试工作方式的一部分,并不意味着某些东西已经崩溃。 Visual Studio 会为您记录这些以防万一您需要它们,但这并不意味着您必须对它们采取行动。

【讨论】:

  • 46 秒。 '关于我制作快照所花费的时间。
  • 谢谢!我能够弄清楚是什么导致了它们。不幸的是,HtppExceptions 已经停止。我会检查他们是否回来。
  • 谢谢。现在我知道:“提供程序与 Oracle 客户端的版本不兼容”。在我检查“CLRE”之前,VS2013 什么也没做。
  • VS2015中:点击菜单Debug,子菜单Windows,异常设置项(快捷键Ctrl-Alt-E),得到一堆可以检查的异常。
【解决方案2】:

谁知道???

但你可以找到。点击 ctrl-alt-E,并在 Exceptions 对话框中指示调试器在抛出异常时中断:

当它中断时,检查 InnerException 属性以查看导致 HttpException 的原因。

【讨论】:

    【解决方案3】:

    查看此 URL 以详细了解这些消息:http://blogs.msdn.com/b/davidklinems/archive/2005/07/12/438061.aspx

    如果您愿意,可以通过以下方式禁用此输出:

    工具 --> 选项 --> 调试 --> 常规 --> 取消选中 将所有输出窗口文本重定向到即时窗口

    【讨论】:

    • 啊哈。所以这告诉我这不是问题,异常会以某种方式得到处理。但它确实表明 System.Web.dll 和 mscorlib.dll 内部出了问题?
    • 那么,这种行为正常吗?甚至 ArgumentOutOfRange 的?捕捉 ArgumentOutOfRange 基于异常的控制流的气味......他们在 mscorlib 中使用它吗?哎哟! @Krumelur 你确定你自己没有抓到那些吗?
    • 是的,第一次机会异常是被抛出和处理的异常。
    【解决方案4】:

    其他(可能有用的)信息:

    在许多原因中,这可能是由于站点/webapp 没有 favicon.ico 文件。

    如果实际异常是:System.Web.StaticFileHandler.GetFileInfo,这显然是找不到文件。如果您在浏览器上没有看到实际的 404 错误,很可能是因为浏览器在找不到 favicon.ico 时悄悄地执行其业务。

    【讨论】:

      猜你喜欢
      • 2015-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-28
      相关资源
      最近更新 更多