One feature of the Visual Studio 2008 SP1 debugger that many .NET developers are unaware of is that it can be used to debug the .NET Framework source itself. Within the Visual Studio 2008 Options dialog are settings that allow you to use a reference source server provided by Microsoft that provides access to the source code for the .NET Framework. In this article I walk you through configuring the Visual Studio 2008 SP1 debugger such that you can step into the .NET Framework itself.
Start Visual Studio 2008 SP1 and then go to the Tools menu and then select Options and locate the the General Debugging section as shown here.
Initially we will unselect the Enable Just My Code (Managed only) option which is selected by default.
Obviously we will want to select the Enable .NET Framework source stepping option.
Visual Studio 2008 SP1 needs to know where to access the framework source code and for this reason we will select the Enable source server support option.
The Visual Studio 2008 SP1 debugger needs to now know which symbols to use when debugging and so you'll want to set the Symbols settings as shown here. If you have Visual Studio 2008 SP1 installed then the Options dialog will look like the following and the two buttons at the bottom of the page are disabled.
If however you are still using the initial RTM build of Visual Studio 2008 then this Options page will be somewhat different. In that version there are two check boxes following the text box where you define the default location to save the symbol files. If you are using the RTM build and have not applied the SP1 update then leave these check boxes unselected.
When you click OK you'll receive the following warning advising you to only use symbol files that are from a known and trusted location. Click Yes to continue.
We will now define a new C# console application with which we can test the .NET Framework source debugging. Call the new project SourceDebugging or some other name of your choice.
Within the Project class we'll add a single statement calling the Console.WriteLinemethod, passing some suitable string. Press F9 on that line to create a debugger breakpoint.
We'll now press F5 to begin debugging and you'll notice the debugger begins downloading the required symbols.
Once the symbols have been successfully downloaded the debugger breaks on the breakpoint as expected.
Here is where the magic begins...
Press F11 to step into the Console.WriteLine method and you'll find that Visual Studio 2008 loads the Console.cs source file into another editor Window and breaks within the InitializeStdOutError method.
You'll notice that you have access to the source code for the Console class although you might not have expected to have access to the comments within the source too.
Until recently framework source debugging was not working on the RTM builds of Windows 7 and Windows Server 2008 R2 because the required symbols for build 7600 were not available from the public symbol servers.
If you are using either an earlier build of these operating systems then framework source debugging is unlikely to work even if you have downloaded the symbols for the build of Windows you are using. Once you have access to the RTM builds however you'll be debugging the .NET Framework source code without issue.
Have fun debugging!!!