Bob Yexley Bob Yexley - 8 days ago 5
C# Question

Application_Start not firing?

I have an ASP.NET MVC (beta) application that I'm working on, and am having trouble figuring out if I'm doing something wrong, or if my

Application_Start
method in Global.asax.cs is in fact not firing when I try to debug the application.

I put a breakpoint on a line in my
Application_Start
method, and am expecting that when I attempt to debug the application that the breakpoint should get hit... but it never does. Not after I reset IIS, not after I reboot, not ever. Am I missing something? Why is this method never getting called?

Answer

If this is in IIS, the app can get started before the debugger has attached. If so, I am not sure if you can thread sleep long enough to get attached.

In Visual Studio, you can attach the debugger to a process. You do this by clicking Debug >> Attach to process. Attach to the browser and then hit your application. To be safe, then restart IIS and hit the site. I am not 100% convinced this will solve the problem, but it will do much better than firing off a thread sleep in App_Start.

Another option is temporarily host in the built in web server until you finish debugging application start.