0

I am trying to debug asp.net mvc source code. Here are the steps I took:

  1. I set up a bare-bone asp.net mvc application (version 5.2.4) by using the template offered by Visual Studio 2017.

  2. I downloaded asp.net mvc source code from offcial github, and according to this, MvcHandler will be hit in the code path so I put a breakpoint in its processRequest() method.

  3. I follow the instruction from the microsoft reference web (there is a link on the main page) about how to set up VS and I use "https://referencesource.microsoft.com" as symbol server.

  4. During debugging, I also make sure "System.Web.Mvc.dll" is loaded (dll for MvcHandler).

I think I get both source code and pdb, but I still get error: "no symbol has been loaded for this document". I want to know what other steps I can take to solve this.

Some other posts I read:

(1) can't debug asp.net MVC

(2) same error message

user2628641
  • 2,035
  • 4
  • 29
  • 45
  • You can try `Cleaning` your solution or try this: Debug=>Options=>General => Remove the check mark for "Enable Just My Code" – Rahul Sharma Apr 02 '19 at 16:34
  • @RahulSharma I tried both but no luck :( – user2628641 Apr 02 '19 at 18:14
  • There could many reasons why you are getting this error. I believe this link would help you in your problem: https://developercommunity.visualstudio.com/content/problem/97445/vs2017-the-breakpoint-will-not-currently-be-hit-no.html – Rahul Sharma Apr 03 '19 at 11:09
  • Your 1st link in point #3 doesn't go to where you intended it to, I think. – Ian Kemp Apr 04 '19 at 04:42
  • @IanKemp I updated the description, there is a link near the top of that page. According to "(2) same error message", I suspect the code is undebuggable (the Zi parameter), but can't know for sure – user2628641 Apr 04 '19 at 04:48

2 Answers2

1

There should be no need for you to download the MVC 5 source code, the whole point of symbols and source servers is to fetch those source files for you as needed while debugging.

I use "https://referencesource.microsoft.com" as symbol server

That's likely your problem - Reference Source is only for the .NET Framework. In order to get MVC 5 symbols and source files, you need to add a different symbol server, such as SymbolSource - see http://www.symbolsource.org/Public/Wiki/Using.

You should also be aware that a lot of the information around debugging with symbols is outdated. In particular, in VS 2017 and later, there is a new option under Tools > Options > Debugging > General called "Use managed compatibility mode", which should be unchecked.

If all else fails, since you already have the MVC source on your machine, simply point your solution at - either by removing the MVC DLL references and including and referencing the relevant projects in your solution, or by replacing the MVC DLL references with references to your own locally-compiled DLLs. This is a lot more pain and effort than using symbol servers, but it's also 100% reliable.

For troubleshooting purposes, the Modules window (Debug > Windows > Modules when debugging) is invaluable; it will show you what DLLs were loaded by your project, what PDBs were loaded for them and where from, and if a PDB wasn't loaded it will tell you why. You can also manually force a PDB to be loaded via right-clicking a particular DLL and browsing to its location.

See also: Debugging Asp.net MVC 5.2.3 source code

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
  • Really appreciate the help. I tried your suggestion but still get the same error message. But building the code locally seems promising. I avoided it before because it's more work but seems like it's my only choice left.... – user2628641 Apr 05 '19 at 04:06
  • unfortunately, building locally also doesn't work. Because of https://stackoverflow.com/questions/20212035/how-to-fix-could-not-load-file-or-assembly-xxx-or-one-of-its-dependencies-st, which is annoying. Someone else also share my frustration: https://stackoverflow.com/questions/51337092/cannot-step-into-mvc4-methods – user2628641 Apr 05 '19 at 04:52
0

I solved my problem. Instead of using Asp.net Mvc 5.2.4, I downloaded the latest Mvc package here: https://dotnet.myget.org/feed/aspnetwebstack-dev/package/nuget/Microsoft.AspNet.Mvc and that does the trick for me (Everything else I did stay the same).

So if one version doesn't work for you, try a different version!

user2628641
  • 2,035
  • 4
  • 29
  • 45