tags:

views:

980

answers:

5

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? Any ideas?

A: 

I think the application start event only gets fired when the first request is made, are you hitting your website (i.e. making a request)?

ninj
Yes I am making a request to the application.
Bob Yexley
+1  A: 

When you say "debug", do you mean actually launching the application from Visual Studio's built-in webserver for debugging, or do you mean attaching to the process in IIS? If it's the former, you should hit Application_Start, but if it's the latter, it can be difficult to be on the process early enough to catch it.

Rex M
Correct, I do mean launching the app from VS. I have it hosted in IIS, so VS is attaching to that process. Are you saying that the event fires before before VS can attach to the process?
Bob Yexley
A: 

Have you tried creating a new empty solution?

Jonathan Parker
Sorry...I don't follow how that would help me?
Bob Yexley
Sorry, I mean empty as in a new vanilla MVC project without any of your own code.
Jonathan Parker
+4  A: 

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.

Gregory A Beamer
+2  A: 

I'm too having problems with breakpoints in application_start with IIS a hosted app. A good workaround is using Debugger.Break(); in code instead of the VS breakpoint

Flores
I belive that not hitting the breakpoint as something to do with running your app pool in integrated pipeline mode. Are you using that?
Flores