By

Debugging ASP.NET MVC Source Code

This is more for my memory than anything else, but hopefully will be useful for others too.

To debug the ASP.NET MVC source code you need the following steps:

  1. Go to Tools > Options and tick Enable .NET Framework source stepping.
  2. Did it work? If not (like me) continue with the rest of these steps.
  3. First off download the source code. I’m going to be debugging version 2 .
  4. Once downloaded, extract the zip out (you may want to unblock it first [Right click on the ZIP, Properties > Unblock)
    Otherwise you may hit issues when trying to debug later.
  5. Add the System.Web.Mvc.csproj as an existing project in Visual Studio.
  6. Replace the normal MVC reference in your web project with the new project with the source code.
  7. Open the web.config (the one in the root, not the one in Views):
  8. Comment out {add assembly=“System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL” /}
  9. Add in {add assembly=“System.Web.Mvc” /}
  10. Do a Clean, then Rebuild.
  11. Bit of luck, jobs a good ‘un.

28th Sep 2010 Addendum

I’ve subsequently come across an article that outlines an alternative method by using the source code server in Visual Studio.

I’ve had a go, but I couldn’t get anything coming out of the watch windows (due to the assemblies being optimised) which kind of limits what you can do (unless I’m doing something wrong – please add a comment if I am!).

Posted in : code, debugging, development

Written by
Founder, Developer, tea maker