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?
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
Checking Tools
-> Options
-> Debugging
-> General
-> Enable source server support
mysteriously made everything work. I hope the same is true for you
This took me an hour as well. I fixed it finally by resetting the Settings -> Tools -> Import and Export Settings -> Reset all settings
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.
Clean the solution before build solved the issue for me.
Just navigate and click on:
Build -> Clean Solution. Build -> Build Solution (Ctrl + Shift + B).
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,
https://i.stack.imgur.com/hxo7W.png
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.
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
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.
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
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.
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.
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.
I had this error after using the checkbox to make single instance application in the program properties section:
https://i.stack.imgur.com/8gjec.png
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.
Success story sharing