Search code examples
asp.net-mvcdebuggingcompilation

Why does not the Application_Start() event fire when I debug my ASP.NET MVC app?


I currently have the following routines in my Global.asax.cs file:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.MapRoute(
        "Default",                                          
        "{controller}/{action}/{id}",                       
        new { controller = "Arrangement", action = "Index", id = "" }
    );
}

protected void Application_Start()
{
    RegisterRoutes(RouteTable.Routes);
    // Debugs the routes with Phil Haacks routing debugger (link below)
    RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
}

Routing debugger...

When I hit F5, the application fires up and unless I have a view named Index.aspx in the ~/Views/Home/ folder, I get the "View missing" error message, although I have re-defined the default route and removed the HomeController. I would expect to get the routing debugger, and if not that at least a request for ~/Views/Arrangement/Index.aspx.
A breakpoint on RegisterRoutes(Routetable.Routes); is never hit when debugging.

I have tried building, rebuilding, restarting VS, cleaning, rebuilding again etc, but nothing seems to work. Why doesn't the application run the current version of the code?


Solution

  • I found the problem:

    This MVC application was part of a larger solution, in which I had at one point set another project to build for an x86 environment (I'm running x64). When I did that, apparently all other projects - even those added later - were set not to build on Ctrl+Shift+B, and I suppose that's why the debugger didn't hit my breakpoint.

    Solution:

    Go into the solution build properties (right-click Solution, select properties, and select Build on the menu on the left), and put a check in the Build checkbox next to the project name in the list.