Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place breakpoints in system.web.mvc before starting an app?

I would like to learn how ASP.NET MVC's model binder works by placing breakpoints in some methods which execute before my action method executes. For example placing them in DefaultModelBinder class. I went through the route of adding some of MVC's projects sources into my solution (like System.Web.MVC, System.Web.Razor, System.Web.WebPages,System.Web.Helpers...) so I can run my versions of them and place breakpoints where I like but I got an error "Could not load file or assembly 'System.Web.Mvc' or one of its dependencies. Strong name signature could not be verified". I am using a third party signed component which references System.Web.MVC and I think that's what's causing the error.

Are there other ways to trace into System.Web.MVC code before my code runs? I am aware of setting up Visual Studio to get the relevant symbols from the symbols servers but I don't know how to place breakpoints in .NET's code before my own code runs.

like image 336
Tony_Henrich Avatar asked Oct 05 '15 05:10

Tony_Henrich


1 Answers

I was able to set breakpoints and they would get hit.

  • Set up VS to load symbols from the symbol servers.
  • Set a breakpoint in your app
  • When the breakpoint is hit, open the Modules window and set System.Web.Mvc.dll to automatically load its symbol file
  • Run the app again in debug mode. When the breakpoint is hit, open the Call Stack window. Select an interesting line which is in System.Web.Mvc.dll. These lines should be contrasted which means their source is available (I guess).
  • Right Click on the line and select 'Go to Source Code'. A dialog box opens wanting you to locate the source file.
  • I have the source code for System.Web.Mvc so I open the source file.
  • Set up some breakpoints in it.
  • Run the app again in debug mode. Now those breakpoints inside System.Web.Mvc will get hit.
  • (I assume I can open any source file in System.Web.Mvc in VS and set breakpoints in it and they will get hit. I assume also the breakpoints get hit even though my file is not in the same location as the original location in the symbol file because I have 'Require source files to exactly match the original version' settings turned off. I need to verify these assumptions)
like image 165
Tony_Henrich Avatar answered Sep 21 '22 18:09

Tony_Henrich