How do I debug .NET 4.6 framework source code in Visual Studio 2017?

Use the Symbol Server feature in JetBrains dotPeek. Worked like a charm for me after struggling to get the standard functionality to work:

  1. Run dotPeek and go to Tools > Options... > Symbol Server.
  2. Ensure that "All assemblies" is selected and copy the local symbol server URL to the clipboard. Start the dotPeek symbol server by clicking it in the Tools menu.
  3. In Visual Studio, go to Tools > Options... > Debugging > Symbols and add the dotPeek server URL to the list. Move the dotPeek symbol server as high up the list as possible, and uncheck all other symbol servers in the list (in particular, the "Microsoft Symbol Servers" and "NuGet.org Symbol Server" must not be selected).
  4. Start debugging - when you attempt to step into Framework source code, you will see dotPeek doing some work decompiling the assembly for you, and then you will be into its source.

If this doesn't work, it's probably because Visual Studio has previously downloaded the "wrong" symbols for the assembly in question from Microsoft/NuGet, and is using them instead of asking dotPeek. To check this, start debugging and find the relevant assembly in the modules list (Debug > Windows > Modules) - delete the PDB file at the path displayed under "Symbol File" for that assembly, then restart debugging, and dotPeek should kick into action.


Here is the answer, thanks to Hans Passant. Note that this solution raises additional questions.

  1. Ensure https://referencesource.microsoft.com/ contains the exact version you're debugging.

    • How? Reference source specifies ".NET Framework 4.6.2" but a module version is something like: "4.6.1586.0"
    • You may need to uninstall security updates as explained here: How do you enable "Enable .NET Framework source stepping"?
  2. Configure Visual Studio as specified here: https://referencesource.microsoft.com/setup.html

    • Untick "Enable Just My Code"
    • Tick "Enable .NET Framework source stepping" (this should have been the only step needed)
    • Tick "Enable source server support"
    • Untick "Require source files to exactly match the original version"
  3. Confirm symbols are loaded in the Modules window, with source indexing included.

    • How can you tell if source indexing is included? The modules window doesn't specify if a PDB has stripped source information.

Microsoft could make this process a lot more robust by giving helpful error messages instead of silently failing.