Cannot find .cs files for debugging .NET source code

C#.NetDebugging

C# Problem Overview


I tried setting up debugging the .NET source by following this MDSN walkthrough. The Symbol cache is setup properly, as is the check 'Enable .NET Framework source stepping'.

But subsequently, whenever I want to step into .NET code, I am prompted to specify the location of the relevant cs file. The error message is 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 offered to browse for the file (but I don't have it) or view a disassembly (but I don't want that).

How to step into the .NET source code?

C# Solutions


Solution 1 - C#

Well, in my case I was not trying to debug the .Net framework, but I was getting the same error: Cannot find .cs files for debugging .NET source code. So I had to turn on the "Enable just my code" option under:
Tools -> Options -> Debugging -> General -> Enable just my Code

Per MS docs:

> You can configure Visual Studio to automatically step over system, framework, and other non-user calls and collapse those calls in the call stack window.

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

Solution 2 - C#

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

Solution 3 - C#

This took me an hour as well. I fixed it finally by resetting the Settings -> Tools -> Import and Export Settings -> Reset all settings

Solution 4 - C#

I've tried all the answers from above and nothing worked.

This solved it for me:

Debug -> Delete all Breakpoints

and it solved the problem! So many different things causing this issue.

Solution 5 - C#

Clean the solution before build solved the issue for me.

Just navigate and click on:

  1. Build -> Clean Solution.
  2. Build -> Build Solution (Ctrl + Shift + B).

Solution 6 - C#

The answers here all talk about ignoring/avoiding the source code instead of actually stepping into it.

@JBSnorro is on the right track but the issue is Microsoft doesn't appear to publish all the .NET symbols/source you might encounter. I don't know if it is intentional on their part but to step into MS sources they need to publish every version of every 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 lacking symbols and/or decompiled source. So I couldn't step into common source code like Dictionary.cs or Task.cs as examples. Since MS symbol server's source & symbols likely change all the time. My issue may be resolved by the time you read this?

When I debug the same solution in Jetbrain's Rider, I can see and step through every class in every .NET assembly with no issue. However in VS I can only step into some class but not into others?

If you are really committed to stepping into all .NET source code you can use Jetbrain's DotPeek and decompile the .NET assemblies to actual .cs files to your disk. Then when you see this,

Example of source code not found

You can now browse your disk to the source code you decompiled using DotPeek. Just make sure you decompiled the same assembly version you reference in your project. If not, the symbols may not match up with the correct source line numbers.

Instead, If you just want to hide this "Source Not Found" from constantly appearing and you don't care to step into the code there are no sources for, read @Alex Sherman's answer. You will need to figure out what assembly the offending file is contained in, then add that assembly name to the exclusion list.

Food for thought, I'm not a fan of Rider over VS. Rider is still a touch raw and lacks the crazy amount of built in tooling VS has. However!! I like to have it installed side-by-side in cases like this where I know I can get deeper into the weeds.

Solution 7 - C#

Go to Tools -> Options -> Debugging -> and make sure "Enable Just My Code" is checked true.

This works for me. Make sure to upvote IT WORKS

Solution 8 - C#

If the error is from looking for "nullable.cs" or some other core source file:

You can disable symbols for specific modules by using Debug -> Options -> Debugging -> Symbols and then on the bottom Specify Excluded Modules.

This is useful for cases where you do want to disable "Just My Code" to step into other assemblies that you have PDBs for. Visual Studio I think comes with symbols for mscorlib.dll but does not include the source so sometimes stepping into things will look for a "nullable.cs" or some other core source file.

Solution 9 - C#

Had the same issue, neither proposed above solutions helped me to solve the problem. Occurred in VS 2017. When I ran the project in Visual Studio 2019, everything worked. So just try to run it in other environments. Hope this answer will help someone

Solution 10 - C#

I got this error when updating a NuGet package in a project, while missing to update it in other projects of the solution.

Going to the NuGet Manager of the solution and using the consolidate function, which ensures all projects in the solution use the same version, resolved the problem for me.

Solution 11 - C#

In my case I wound up renaming the class. Maybe it was getting confused with some other module. Once I had renamed it I could step in.

Solution 12 - C#

I was having the same issue. Enable Just My Code and Enable source server support were already checked.

But my issue was not that. The csproj file had an extra tag without its opening tag.

I removed it and the issue resolved.

Hope it helps someone who is facing this issue.

Solution 13 - C#

I had this error after using the checkbox to make single instance application in the program properties section:

Make single instance application

It was strange that it didn't throw an error before this. The program would crash every time suddenly on startup and not break on a line that showed I didn't have a code error.

After unchecking the "Make single instance application", the program fired right up.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJBSnorroView Question on Stackoverflow
Solution 1 - C#dierView Answer on Stackoverflow
Solution 2 - C#JBSnorroView Answer on Stackoverflow
Solution 3 - C#StefanView Answer on Stackoverflow
Solution 4 - C#HomeMadeView Answer on Stackoverflow
Solution 5 - C#Shahar ShokraniView Answer on Stackoverflow
Solution 6 - C#Eat at JoesView Answer on Stackoverflow
Solution 7 - C#AdamLView Answer on Stackoverflow
Solution 8 - C#Alex ShermanView Answer on Stackoverflow
Solution 9 - C#OlegIView Answer on Stackoverflow
Solution 10 - C#RonnyRView Answer on Stackoverflow
Solution 11 - C#KirstenView Answer on Stackoverflow
Solution 12 - C#Arjun MGView Answer on Stackoverflow
Solution 13 - C#SoftwareCreationsView Answer on Stackoverflow