Почему ASP.NET выбрасывает так много исключений? - PullRequest
25 голосов
/ 30 марта 2011

По стечению обстоятельств я немного посмотрел отладочный вывод Visual Studio.Я вижу сотни и сотни различных исключений.Я проверил другое решение на основе ASP.NET, и оно показывает то же поведение.Почему выбрасываются все эти исключения?Я не могу поверить, что это хорошо для общей производительности, не так ли?Посмотрите на выдержку ниже.Это вывод ок.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 ]

35 голосов
/ 30 марта 2011

Я не совсем точно знаю, что это вызывает, но я знаю, как вы можете узнать (даже лучше, верно? :)).

В Visual Studio:

  • Нажмите в меню «Отладка»
  • Нажмите «Исключения ...»
  • Установите флажок «Брошено» в «Общих исключениях времени выполнения»

Это заставит Visual Studio остановить отладчик в любом исключении, чтобы вы могли проверить, что на самом деле происходит. (не влияет на производственный код, останавливается только в VS)

В качестве идентификатора вы можете захотеть внедрить что-то вроде автоматической отправки исключений по электронной почте или подобное, чтобы получить больше информации с рабочего сайта.

Обратите внимание, что вы, возможно, не сможете перехватить все исключения в VS из коробки (исключения первого раза иногда могут быть немного неуловимыми). Если вы хотите быть более хардкорным, вы можете использовать отладчик Visual Studio для отладки .Net Framework . Ваша цель должна состоять в том, чтобы увидеть полное исключение + трассировка стека, которое в большинстве случаев расскажет вам все о том, что идет не так.

Хорошей практикой является избавление от исключений (найти причину и исправить), не скрывать и не игнорировать их.

EDIT

Также ничего не стоит, что « исключения первого шанса » - это исключения, которые вполне могут быть захвачены при попытке попробовать. Некоторые внутренние функции в .Net будут генерировать исключение при выполнении определенного условия, это является частью работы Visual Studio / отладки и не означает, что что-то не получилось. Visual Studio запишет их для вас на тот случай, если они вам понадобятся, но это не значит, что вы должны действовать в соответствии с ними.

23 голосов
/ 30 марта 2011

Кто знает ???

Но вы можете узнать.Нажмите ctrl-alt-E и в диалоговом окне «Исключения» дайте отладчику команду прерваться при возникновении исключения:

exceptions dialog

Когда оно прервется, отметьте InnerException свойство, чтобы увидеть, что вызвало HttpException.

4 голосов
/ 30 марта 2011

Посмотрите на этот URL для подробного просмотра этих сообщений: http://blogs.msdn.com/b/davidklinems/archive/2005/07/12/438061.aspx.

Если хотите, вы можете отключить этот вывод, перейдя в:

Инструменты -> Параметры-> Отладка -> Общие -> снимите флажок Перенаправить весь текст окна вывода в окно немедленного действия

2 голосов
/ 02 ноября 2011

Дополнительная (возможно, полезная) информация:

Среди многих причин это может быть вызвано тем, что сайт / веб-приложение не имеет файла favicon.ico.

Если фактическое исключение: System.Web.StaticFileHandler.GetFileInfo, это, очевидно, файл не найден. И если вы не видите фактическую ошибку 404 в браузере, скорее всего, потому что браузер спокойно работает, когда не находит favicon.ico.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...