tom greene
tom greene

Reputation: 5449

How can I step into Microsoft's .NET framework source code?

I'd like to step into Microsoft's source code but cannot.

I followed the instructions at Configuring Visual Studio for Debugging. In particular, I disabled "Enable Just My Code" and Enabled "Enabled .NET Framework source stepping". Finally, set the source symbol location to "http://referencesource.microsoft.com/symbols".

However, when I double click on a frame item on the stack, I get some assembler code, not C# code. Also the "go to source code" menu item is disabled.

I am using Visual Studio 2008 SP1 and .NET 3.5 SP1. I created a brand new folder for the downloaded stuff. I get some pdb files but no C# file.

I looked at Configuring Visual Studio to Debug .NET Framework Source Code and installed the path. It makes no difference. I am trying to the source code of WPF. The pdb are downloaded so it looks like Microsoft supports those.

Is there a trick to fix this?

Upvotes: 9

Views: 6406

Answers (3)

Hemendr
Hemendr

Reputation: 1038

I applied these steps for VisualStudio 2022

  • Enable Microsoft Symbol Servers: To allow Visual Studio to automatically download the symbols from Microsoft's servers. (See Fig-1) Tools > Options > Debugging > Symbols. Check the box next to
    "Microsoft Symbol Servers" to enable it
  • Enable Source Link Support (Visual Studio 2017 and later): This feature allows you to download and step into the source code from repositories that support Source Link. (See Fig-2) Tools > Options > Debugging > General > Check the box next to "Enable Source Link Support" to enable it
  • Disable Just My Code: This option allows the debugger to step into code that's not part of your project, including .NET Framework code. (See Fig-2) Tools > Options > Debugging > General > uncheck the box next to "Enable Just My Code" to disable it.
  • Enable source server support: This option allows the debugger to retrieve source code files (like the .NET Framework for which you may not have the source code locally) from Microsoft Reference Source servers during debugging. (See Fig-2) Tools > Options > Debugging > General > Check the box next to Enable source server support to enable it.

To Start Debugging

Since symbols and source files are downloaded from Microsoft's servers you need an active internet connection. Now Set a breakpoint in your .net code where you wish to start debugging. As soon as you run the application in Debug mode for the first time after completing the above steps Visual Studio might take a moment to download the necessary symbols and source files from the Microsoft servers (See Fig-3). Subsequent debugging sessions should be faster.

When breakpoint hits at code that's part of the .NET Framework and you choose to step into. If the .net code is a property or operator (e.g.: ?) then you are prompted a dialogue box saying “Your step-into request resulted in an automatic step-over of a property or operator.”. So Visual Studio will not step into that code. If you still want to step into Property or operator then

  • you have to uncheck the option of “Step over properties and operators (Managed only)” to disable it as shown in Fig-2 or
  • You can choose to step into specific using the Context menu of the line being executed where the breakpoint hit as shown in Fig-4.

enter image description here

enter image description here

enter image description here

enter image description here

Upvotes: 0

KristoferA
KristoferA

Reputation: 12397

Not all parts of the .NET framework is available as reference source, but the parts that are (and steps for getting it up and running) is described in Shawn Burke's blog, Configuring Visual Studio to Debug .NET Framework Source Code.

Update: Hmm. It is broken on my machine too although it used to work. Weird.

Upvotes: 2

gix
gix

Reputation: 5797

As far as I have observed .NET framework stepping with the reference source works just fine with the guides you find everywhere. With VS SP1 you don't even have to add the path to the reference source server.

But the problem are mismatched versions. The framework assemblies were updated with .NET 3.5 SP1, Vista SP2, Windows 7, ... but their reference source PDBs weren't made available. The corresponding reference source forum seems quite dead, too. I remember reading that it took them a bit longer to push out the initial symbols because they built an infrastructure that would allow them to push new versions quickly. Either that didn't really happen or they don't use it.

Upvotes: 3

Related Questions