为什么ASP.NET会抛出这么多异常?

时间:2011-03-30 14:31:24

标签: asp.net iis

巧合的是,我看了一下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

4 个答案:

答案 0 :(得分:35)

我不确定究竟是什么导致它,但我知道你怎么能找到(更好,对吧?:)。)

在Visual Studio中:

  • 点击“调试”菜单
  • 点击“例外情况......”
  • 检查“公共语言运行时异常”
  • 上的“Thrown”

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

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

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

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

修改

同样值得一提的是“first chance exceptions”是一个例外,很可能被try-catch捕获。 .Net中的某些内部函数会在满足某个条件时抛出异常,这是Visual Studio /调试工作方式的一部分,并不意味着某些事情已经崩溃。 Visual Studio将为您记录这些内容,以防您需要它们,但这并不意味着您必须对它们采取行动。

答案 1 :(得分:23)

谁知道???

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

exceptions dialog

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

答案 2 :(得分:4)

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

如果您愿意,可以通过转到:

来禁用此输出

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

答案 3 :(得分:2)

其他(可能有用)信息:

在众多原因中,这可能是因为网站/ webapp没有favicon.ico文件。

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