Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
843 views
in Technique[技术] by (71.8m points)

debugging - Debug .NET Core source (Visual Studio 2019)

I use Visual Studio 2019 and a .NET Core 3 web application. I'd like to debug .NET Core source code, so when an error occurs I can dive into the code and examine it in more detail. As I couldn't find an exact description on how to do it (even on the Microsoft documentation site), I'll try to summarize here what I know so far.

I have the following options in Visual Studio:

  1. Enable just my code
  2. Enable .NET framework source stepping
  3. Enable source server support
  4. Enable source link support

The first two options are mutually exclusive. I suppose I should select the second option, although I don't understand weather ".NET framework" in this options includes .NET Core?

Now as .NET Core is open source and available on GitHub, I don't understand third vs. fourth option. The third should allow me to pull source from Microsoft Symbol Servers (do symbols include source?) while the fourth should allow me to pull source from GitHub? Do I need one or the other?

First, I put a breakpoint on CreateHostBuilder in the Main method, select the third option and run the application. After the breakpoint is hit, I keep stepping into code (F11) until a message appears saying "GenericHostBuilderExtensions.cs is not found". It offers me to browse for it, but I have no idea where could I find it.

Let's try all over again, this time selecting the fourth option (and deselection the third). Now, after the breakpoint is hit, Visual?Studio offers me to download the before mentioned file by Source Link. I accept, but the result is the message

Source Link Error: Azure DevOps: Authentication failed for all accounts. Use 'File -> Account Settings...' to add a new account or refresh credentials.

Well, I'm logged in with my Microsoft account. What else should I do?

I repeat it all again, this time selecting both third and fourth options. The result is the same.

Now I select another Source Link option: "Fall back to Git Credential manager..." and start all over again. The same result.

Of course, I extensively googled and spent quite some time trying to find a solution, but I'm missing something. I'd appreciate help on what exactly the mentioned options do and how to debug by stepping into .NET Core source code.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Maybe this issue can help solve your puzzle.

Just like what vancem describes in that issue, all you need to do for debugging .net core source is:

1.Uncheck the (Tools -> Options -> Debugging -> Just My Code) checkbox.

2.Ensure that the (Tools -> Options -> Debugging -> Symbol Settings -> Microsoft Symbol Servers) checkbox is set

3.Ensure that the (Tools -> Options -> Debugging -> Enable Source Link support) checkbox is checked

"GenericHostBuilderExtensions.cs is not found".

As for why you fail here. I think it's similar to the issue I provides above. For .net core 3.0 preview, some of its libraries currently don't have source links in github so the vs can't fetch them. (Like .net core 2.0 in 2017, now it has been fixed)

Actually, if you follow options above, you will find you can debug well .net core 2.x web-app, but may fail for not finding source links for .net core 3.0.

As a workaround:

1.You can try getting the source manually from git, and go solution -> Properties -> Debug Source Files, then add your directory to the 'Directories Containing Source Code' to check if it helps for some situation. (Which is describe in details by vancem, thanks to him)

2.And the source of GenericHostBuilderExtensions.cs of the GenericHostBuilderExtensions.cs can be found here.I reproduced same issue, and resolve it by download the xx.cs and find it during debugging.

3.But I have to say this way takes some time. Since not only this file has no source file, we will meet similar issues and have to resolve it by getting corresponding source from git unless all the source in .net core3.0 has its source links. But it may takes some time, sorry for this inconvenience. And I suggest you can post it on github and share link here. Members interested in it will help vote it.

Hope all above helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...