Cannot find .cs files for debugging .NET source co

2020-01-29 04:09发布

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?

10条回答
叼着烟拽天下
2楼-- · 2020-01-29 04:38

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.

查看更多
爷、活的狠高调
3楼-- · 2020-01-29 04:39

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

查看更多
叛逆
4楼-- · 2020-01-29 04:43

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).
查看更多
Ridiculous、
5楼-- · 2020-01-29 04:47

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

查看更多
霸刀☆藐视天下
6楼-- · 2020-01-29 04:49

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.

查看更多
7楼-- · 2020-01-29 04:51

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

查看更多
登录 后发表回答