Cannot find .cs files for debugging .NET source code

I tried to configure .NET source debugging by doing the following MDSN walkthrough . The Symbol cache is configured correctly, as is the check box for "Include .NET Framework Initial Step".

But subsequently, whenever I want to enter the .NET code, I will be asked to indicate the location of the corresponding cs file. Error message You need to find <filename>.cs to view the source for the current call stack frame and The debugger could not locate the source file <filename>.cs .

I am prompted to view the file (but I don’t have one) or view the disassembly (but I do not want this).

How to enter .NET source code?

+53
debugging c # .net-framework-source
source share
10 answers

Checking Tools Options Debugging General Enable source server support mysteriously made everything work. I hope the same is true for you.

+36
source share

Well, in my case, I did not try to debug the .Net infrastructure, but I got the same error: Could not find .cs files for debugging .NET source code . So I had to enable the option "Include only my code":
Tools β†’ Options β†’ Debugging β†’ General β†’ Include only my code

In MS docs:

You can configure Visual Studio to automatically navigate system calls, frameworks, and other non-user calls and collapse these calls in the call stack window.

https://docs.microsoft.com/en-us/visualstudio/debugger/just-my-code

+81
source share

It took me an hour too. I fixed it by resetting the settings -> Tools β†’ Import and Export Settings β†’ Reset

+14
source share

The answers here all talk about ignoring / excluding the source code, rather than entering into it.

@JBSnorro is on the right track, but the problem is that Microsoft does not publish all the @JBSnorro characters / source you may encounter. I don’t know if they intentionally do it, but in order to get into the MS sources, they need to publish every version of each assembly, which is a big logistical task.

Tools Options Debugging General Enable source server support will work in many cases, but I found, for example, mscorlib.dll for 4.6.1 was missing characters and / or a decompiled source. Therefore, I couldn’t go into common source code, such as Dictionary.cs or Task.cs since the source and symbols of the MS symbol server probably change all the time. My problem can be solved by the time you read this?

When I debug the same solution in Jetbrain Rider, I see and view each class on every .NET assembly without any problems. However, in VS, I can only enter into some class, but not into others?

If you are really ready to go into all of the .NET source code, you can use Jetbrain DotPeek and decompile the .NET assemblies into actual .cs files on your disk. Then when you see it,

Example of source code not found

Now you can view your disk in the source code that you decompiled with DotPeek. Just make sure you decompile the same build version that you specified in your project. If not, the characters may not match the correct source line numbers.

Instead, if you just want to hide this "source not found" from the constant appearance, and you do not want to enter the code, there are no sources for it, read @Alex Sherman answer. You will need to find out in which assembly the malicious file is located, and then add this assembly name to the exclusion list.

Food for thought, I'm not a fan of Ryder over VS. The rider is still sensed by touch and lacks the crazy amount of VS built-in tools. Anyway!! I like it to be planted side by side in cases where I know that I can penetrate deeper into the weeds.

+2
source share

If the same problem arose, none of the solutions suggested above helped me solve the problem. It happened in VS 2017. When I started the project in Visual Studio 2019, everything worked. So just try to run it in other environments. Hope this answer helps someone

+1
source share

If the error is related to finding "nullable.cs" or another kernel source file:

You can disable characters for specific modules using Debug β†’ Options β†’ Debugging β†’ Symbols and then below. Specify Excluded Modules .

This is useful for cases when you want to disable "Just My Code" to switch to other assemblies for which you have a PDB. Visual Studio I think it comes with characters for mscorlib.dll but does not include the source, so sometimes things will look for "nullable.cs" or some other main source file.

0
source share

Clearing the solution before building solved the problem for me.

Just go and click on:

  1. Build β†’ Clean Solution .
  2. Build Build Solution (Ctrl + Shift + B) .
0
source share

To get to the .net source code, you may need to download it from here: https://referencesource.microsoft.com/#mscorlib/system/runtime/remoting/realproxy.cs

0
source share

You can find the source code here for download so you can debug correctly. https://referencesource.microsoft.com/#mscorlib,namespaces

0
source share

I got this error when updating a NuGet package in a project, but could not update it in other solution projects.

Switching to the NuGet manager of the solution and using the consolidation function, which ensures that all projects in the solution use the same version, solved the problem for me.

0
source share

All Articles