Cannot find .cs files for debugging .NET source code
Checking Tools
-> Options
-> Debugging
-> General
-> Enable source server support
mysteriously made everything work. I hope the same is true for you
I'm not able to debug .NET Core source code
Did you enable Source Link? I was able to step into the .NET Core 3.1 source code after doing the following:
Uncheck "Enable Just My Code" and check "Enable Source Link support" in Tools -> Options -> Debugging -> General
Activate the symbol servers in Tools -> Options -> Debugging -> Symbols
I got this information from Improving Debug-time Productivity with Source Link on Microsoft Devblogs.
How to debug into .NET framework source code
First of all, I tested it using Microsoft Visual Studio Enterprise 2017, Version 15.9.7 and via .NET Framework 4.7.2. Though, I think it should work on Community edition the same way.
Steps to take:
Go to Tools / Options / Debugging / General, and perform these settings:
- check Enable .NET Framework source stepping (this will automatically disable "Enable Just My Code"; if not, do it manually)
- uncheck Require source files to exactly match the original version
- check Enable source server support
Go to Tools / Options / Debugging / Symbols, and:
- in the upper listbox check Microsoft Symbol Servers
- click Empty Symbol Cache button (to make sure you will get the correct symbols)
- select Load all modules, unless excluded radio button at the bottom
Download the source of the .NET framework version your project is targeting, from the https://referencesource.microsoft.com/download.html site.
Unpack the downloaded archive (zip) file to a convenient path on your PC.
Debug your application; set a breakpoint to the line of .NET code you wish to debug, and step to the desired code line with the debugger.
Note: your application may start slower since it will download PDBs from the internet.
Press Step Into (F11 by default). If your settings are correct, this will cause some delay (if your VS crashes (like mine did), Empty Symbol Cache again). Eventually it will ask for the sources of the given file, e.g.
dictionary.cs
.
Two things can happen here:- A) It asks for the source file (.cs) in a file dialog. Go to step 7.
- B) It says
whatever.cs
not found, and there is a link that says "Browse and find whatever.cs...". Click that link.
Select the corresponding .cs file on your disk (you can search for the file on the OS).
Note: I had to restart VS several times until it "did not crash" while looking for sources, this is most likely a bug in VS.
- If you did everything correctly, you will find yourself debugging the .NET source code.
Note: Since VS saves the path you entered for the source files, you can stop debugging or restart VS; it will work next time, too.
Besides, you do not have to manually select any more source files within the framework, because the VS will use the source folder you entered and will search in source files there.
Related Topics
C# Datagridview Checkbox Checked Event
Crud Operations Using Datagridview, Datatable and Dataadapter - Cannot Add New Row to Datagridview
Error Making Azure Management Library API Call When Authenticating with Azure Active Directory
Image Is Not Drawn at the Correct Spot
Is Unityscript/JavaScript Discontinued
C#: HTMLagilitypack Extract Inner Text
Install to Same Path When Upgrading Application
Generate 16-Bit Grayscale Bitmapdata and Save to File
Jquery Ajax Call to an ASP.NET Webmethod
How to Write the Escape Char '\' to Code
Does C# Support Project-Wide Default Namespace Imports Like Vb.Net
Datagridview Using Sortablebindinglist
Could Not Load File or Assembly 'System.Web.Http 4.0.0 After Update from 2012 to 2013
Should I Take Ilogger, Ilogger<T>, Iloggerfactory or Iloggerprovider for a Library
Convert Datetime to Julian Date in C# (Tooadate Safe)
Hangfire - Multi Tenant, ASP.NET Core - Resolving the Correct Tenant
Is the C# Compiler Smart Enough to Optimize This Code
Running a Method in Backgroundworker and Showing Progressbar