Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is ASP.NET throwing so many exceptions?

Tags:

asp.net

iis

People also ask

How do I stop Visual Studio from breaking on exception?

To turn off stop on exceptions press " Ctrl + Alt + E ". This will open the Exceptions window . Untick "Common Language Runtime Exceptions - Thrown". That would prevent it from pausing from within the delegate, but not when it's rethrown on Wait .

How does ASP.NET handle Web API errors?

You can customize how Web API handles exceptions by writing an exception filter. An exception filter is executed when a controller method throws any unhandled exception that is not an HttpResponseException exception.

How do you handle exceptions in C#?

Use a try block around the statements that might throw exceptions. Once an exception occurs in the try block, the flow of control jumps to the first associated exception handler that is present anywhere in the call stack. In C#, the catch keyword is used to define an exception handler.

Does throwing an exception stop execution C#?

YES. If the exception was inside a try then code inside matching catch blocks or finally block will be executed.


I'm not sure exactly what is causing it, but I know how you can find out (even better, right?:)).

In Visual Studio:

  • Click on "Debug" menu
  • Click on "Exceptions..."
  • Check "Thrown" on "Common Language Runtime Exceptions"

This will make Visual Studio halt the debugger on any exception so you can check what is actually happening. (does not affect production code, only halts in VS)

As a sidenote you may want to implement something like automatic exception emailing or similar to get more info from a production site.

Note that you may not be able to catch all exceptions in VS out of the box (first time exceptions may sometimes be a bit elusive). If you want to be more hardcore you can have Visual Studio debugger debug the .Net Framework too. Your goal should be to see the full exception + stack trace, that will in most cases tell you all about what is going wrong.

A good practice is to get rid of the exceptions (find cause and fix), don't hide or ignore them.

EDIT

It's also worth nothing that "first chance exceptions" are exceptions that may very well be captured by a try-catch. Some internal functions in .Net will throw an exception when a certain condition is met, this is part of how Visual Studio/debugging works and doesn't mean something has crashed. Visual Studio will log these for you just in case you need them, but it doesn't mean you have to act upon them.


Who knows???

But you can find out. Hit ctrl-alt-E, and in the Exceptions dialog instruct the debugger to break when the exception is thrown:

exceptions dialog

When it breaks, check the InnerException property to see what caused the HttpException.


Take a look at this URL for a detailed look at these messages: http://blogs.msdn.com/b/davidklinems/archive/2005/07/12/438061.aspx.

If you like, you can disable this output by going to:

Tools --> Options --> Debugging --> General --> uncheck Redirect all Output Window text to the Immediate Window


Additional (perhaps useful) info:

Amongst many reasons, this could be caused by the site/webapp not having a favicon.ico file.

If the actual exception is: System.Web.StaticFileHandler.GetFileInfo it's obviously a file not found. And if you're not seeing the actual 404 error on the browser, it's likely because the browser quietly goes about its business when it doesn't find favicon.ico.