Scott Hanselman

.NET Framework Library Source Code available for viewing

January 17, 2008 Comment on this post [15] Posted in ASP.NET | Learning .NET | Microsoft | Programming
Sponsored By

It's live and you can give it a try now! Ten minutes ago Shawn and Scott released the hounds. If you'd like to step through .NET Framework Source code, here's what you need to do.

  1. Install this QFE.
    • Note, if you're on 64-bit Windows, read the description as there is a single manual step for 64-bit folks like me.
  2. Go into Tools|Options|Debugging|General and turn off "Enable Just My Code" and turn on "Enable Source Server."
  3. Go to Symbols and add this URL and a local cache path. Make sure "search only when symbols are loaded manually" is checked.

That's it. Crazy. You can get more detail on Shawn's post if you need it. Here's me, just now, stepping into XPathNavigator's GetNamespacesInScope method.

Do note a few things.

  • Loading source the first time will be slow. There's lots of it. It'll be faster the second time.
  • If you can't right click and select Load Symbols from the Call Stack, try Ctrl-Alt-U and right click Load Symbols for the Module you want to step into.

ConsoleApplication1 (Debugging) - Microsoft Visual Studio (Administrator)

Fabulous. Enjoy.

Related Posts

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
January 17, 2008 3:42
So niiiiiiiiiiice! :)
January 17, 2008 4:18
I suppose I don't really need the QFE, though when I go to install it, I get a message saying:

"None of the products that are addressed by this software update are installed on this computer. Click Cancel to exit setup."

However, I definitely have VS2008 installed, running Windows Server 2003.
January 17, 2008 4:28
I prefer to leave "search only when symbols are loaded manually" unchecked. Less to think about when debugging.
January 17, 2008 13:19
Hey Aaron,

yeah, me as well, if NEEDED I manually switch on the the source server. Therefore I propose a new debugging mode. One that is optimized for debugging just your own source in other words something _I_ broke (which I think is about 99% of "debugging time") - and one that is optimized for debugging all known dependencies, when e.g. an exception in the framework occures that I don't understand (which is the other 1%).

Debug into the .NET Framework Source Code

Just a thought. ;)
January 17, 2008 17:24
That's pretty much what "search only when symbols are loaded manually" is, isn't it? It's "Just My Code" debugging with the option to dig into the framework source for those 1% cases.
January 17, 2008 21:23
I like the related posts idea!
January 17, 2008 21:27
yeah, sorry, didn't make that clear enough in my post. What I don't like while using the "search the above locations only when symbols are loaded manually" that I now have to know exactly where the object I am trying to step into is located (by hitting F1, waiting for the help to pop up, go to the class definition and looking up the assembly, hitting ctrl+alt+u, right clicking assembly, hitting load symbols). Or I have to know which dll's also have pdb's, in order to avoid the "Find Symbols" file selection dialog that pops up when I am trying to load the symbols for a dll that is not supported.

Unfortunatelly the Modules page does not help me remembering which dll's have pdb's, since all dll's have the status "Cannot find or open the PDB file" or "Symbols loaded". Maybe I don't actually need my proposed debugging mode. Come to think about it, all I need is a third status: "Cannot find or open the PDB file", "Symbols not loaded" or "Symbols loaded". Then I could simply select all "Symbols not loaded" and hit load symbols all in one go...

ah, whatever, I love the new functionality. :)
January 17, 2008 22:17
Great news Scott!

Every now and then as I browse the source I see a few instances in a file where the code style seems to change, e.g. pretty much all methods put the opening { on a new line, then out of the blue there will be one on the same line as the sig...I wonder if this is the result of some tool that all this has been ran through, or whether it is the remnants of an employee who refused to change their style! :-)

-- Granville
January 18, 2008 2:08
Is there anyway to access the source code on a computer that doesn't have internet access (it is connected to an isolated network)?
i.e. can we download the source and install it on the isolated network ?
January 18, 2008 17:38
Whenever I click the "Install this QFE" link, I get a page with the following message:

The content that you requested cannot be found or you do not have permission to view it.

I've signed in to Live, but I guess I don't have permission to view it. How do I get permission to view it?
January 18, 2008 20:31
I'm getting the same error. Does anyone have an alternative link?
January 18, 2008 21:25
Weird...let me look into it. All you need is a valid Passport/LiveId.
January 18, 2008 21:30
If you're having trouble DOWNLOADING the QFE, try updating your Windows Live Profile

If you're having trouble installing the QFE and you had VS2008 Beta2 on your machine at some point, try running the QFE with the VS2007 DVD in your drive (or it's ISO mounted).
January 23, 2008 0:56
I developed a tool which allows the download of the framework source code without VS2008.
It also enables me to debug the framework source code under VS2005.
I want to release the source code and the tool himself under LGPL.

What is the legal status on the Microsoft side for such a tool?
As far as i see from the licence, there is no such a term that disallows this.

The tool can download whole the source code to the local and allows offline debugging in VS2008 and VS2005 without any addons installed.

Best Regards
Kerem Kusmezer
February 06, 2008 13:02
Grab your copy from :
.NET Mass Downloader

Welcome to the .NET Mass Downloader project. While it’s great that Microsoft has released the .NET Reference Source Code, you can only get it one file at a time while you’re debugging. If you’d like to batch download it for reading or to populate the cache, you’d have to write a program that instantiated and called each method in the Framework Class Library. Fortunately, .NET Mass Downloader comes to the rescue!

Using .NET Mass Downloader
Open a command or PowerShell prompt and navigate to where you extracted the current release. The tool itself is NetMassDownloader.exe and when run without parameters shows the following help screen:
.Net Mass Downloader - (c) 2008 by Kerem Kusmezer, John Robbins

Batch download the Microsoft .NET Reference Source code.

Usage: NetMassDownloader [-file <file>]
[-directory <directory]
[-output <directory>]
[-vsver <version>]
[-force] [-nologo] [-verbose] [-?]

-file - Download an individual file's PDB and source code. You can
specify multiple file parameters. (Short -f).
-directory - Download all the found PDB and source code for all files in
the specified directory. You can specify multiple
directory parameters (Short -d).
-output - The output directory for PDB and source files. The default
directory is the cache directory set in Visual Studio 2008.
By using the cache directory, you'll have the PDB and source
files available to Visual Studio 2008. However, to use the
.NET Reference Source Code with VS 2005, use the -output
switch and in the Options dialog, Debugging, Symbols property
page, add the specified output directory to the "Symbol file
(.pdb) locations." Also, add the directory to the Solution
Properties, Common Properties, Debug Source Files, Directories
containing source code location. The Visual Studio 2005
debugger will automatically load the source code. (Short -o)
-vsver - The Visual Studio version number to use for finding the cache
directory. The default is Visual Studio 2008,
but if you want to use the cache directory for Visual Studio
2005, you would pass '-vsver 8.0' (without quotes) (Short -vs)
-force - If specified, forces the downloading the PDB files into the
symbol server. When downloading to a symbol server if the PDB
exists, it's not downloaded. Using the -output switch will
always download and process the PDB. (Short -fo)
-nologo - Don't show the logo information. (Short -n)
-verbose - Do verbose output. May be worth turning on as the downloading
source code can take a long time. (Short -v)
-? - This help message.
The only required arguments are –file or –directory, both of which can be specified as many times as you’d like. When you specify a directory, only the .DLL and .EXE files from that directory will be processed. If you wanted to download all the source code from binaries in the .NET 2.0 32-bit and 64-bit directories, the command line you’d pass is: -d C:\Windows\Microsoft.NET\Framework\v2.0.50727 –d C:\Windows\Microsoft.NET\Framework64\v2.0.50727.

The main purpose of Net Mass Downloader is to populate the source code download cache for debugging, the default download location is the cache you specified to Visual Studio 2008. The –vsver switch to account for future Visual Studio versions so Mass Downloader could work with future CTPs and versions.

While it’s great to see the .NET Reference Source Code in Visual Studio 2008, there are a lot of developers out there who can’t upgrade yet, but would love to be able to debug into the .NET Reference Source Code. If you specify the -output parameter, the PDB and .NET Reference Source Code will be written to the specified directory. In Visual Studio 2005, place that directory in the Options dialog, Debugging, Symbols property page. In the “Symbol file (.pdb) locations” list box as the first item. Also in the Options dialog, Debugging, General property page, uncheck "Require source files to exactly match the original version." Finally, in each Visual Studio 2005 project go into the solution property pages, Common Properties, Debugging Source Files, and in the "Directories containing source code" add the output directory to the top of the list. That's enough for Visual Studio 2005 to debug into the .NET Reference Source Code.

When you first run Net Mass Downloader, you will be prompted with the current EULA for accessing the source code. If you don’t agree with the Microsoft EULA, clicking the Decline button will not download the source code.

Thanks to the Developer Division at Microsoft. First they released the .NET Reference Source Code, and second for allowing a couple of developers to have some fun and provide a utility for the community. Thank you for using .NET Mass Downloader. We just ask that you log any bugs and features into the project Issue Tracker.

If you have questions about particular pieces of the code, Kerem Kusmezer did the following parts: the PE (Portable Executable) Parser, the PDB Parser, the Webclient Class. and the SrcSrv class. John Robbins did the console driver, testing, and served as Kerem's code monkey.

Kerem Kusmezer and John Robbins

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.