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:
- Go to Tools > Options and tick Enable .NET Framework source stepping.
- Did it work? If not (like me) continue with the rest of these steps.
- First off download the source code. I’m going to be debugging version 2 .
- 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. - Add the System.Web.Mvc.csproj as an existing project in Visual Studio.
- Replace the normal MVC reference in your web project with the new project with the source code.
- Open the web.config (the one in the root, not the one in Views):
- Comment out {add assembly=“System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL” /}
- Add in {add assembly=“System.Web.Mvc” /}
- Do a Clean, then Rebuild.
- 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