ENTERPRISE

NET Debugging : Visual Studio (part 2) - .NET Framework Source-Level Debugging

11/19/2013 8:19:21 PM

2. .NET Framework Source-Level Debugging

Any given .NET application typically utilizes a number of different types defined in the .NET frameworks. Types can range from simple data types to complex Web service bindings, and abstracts much of the underlying complexity associated with using the technology directly. As with any abstraction though, the situation gets a little hairy if you get stuck and need to debug a problematic application. Rather than having to attempt to reverse engineer the abstraction to get clues as to why the application may be failing, it is much easier if source code is available to look at or even better if source code is available to debug with! Luckily, Microsoft recognized this need and published the source code for parts of the .NET framework. The really great thing about this is that not only is the source code available, but it can also be integrated into Visual Studio so that the source-level debugging that all developers have come to expect also works with the published .NET framework source code. Here, we will take a look at what it takes to configure Visual Studio for seamless .NET framework source-level debugging.

Visual Studio Hot Fix

To use the integrated .NET framework source code with Visual Studio, the hot fix located at https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=10443&wa=wsignin1.0 must first be installed.


For source-level debugging to work, the Visual Studio debugger must be told where it can find the source code for the module that is being debugged. Where does it get this information from? It gets it from the corresponding symbol files that are also made publicly available. Much in the same way that Microsoft publishes all public symbols for other available products on the public Microsoft symbol server, so is the case for the .NET framework. The biggest difference, however, is how much information is exposed in the symbol files being exposed. The symbols made available on the public symbol server are “stripped,” meaning that certain information (including source-level information) has been removed from the symbol file. In contrast, the symbols made available for the .NET framework binaries have full debug information including source-level access, which Visual Studio uses to then find the source code published on the Internet. The first step is to tell Visual Studio that we plan on using a source server to access source code during our debug sessions. This can be enabled by selecting the Tools, Options, Debugging, General menu, which brings up the dialog shown in Figure 6.

Figure 6. Enabling source-level debugging

In the Debugging, General page, please uncheck the Enable Just My Code (Managed only) checkbox and check the Enable source server support checkbox.

Next, we navigate to the Symbols page (in the same Options page) to specify the location of the symbol server we want to use, as shown in Figure 7.

Figure 7. Setting the symbol server

In the symbol file locations, we add the following URL, which contains .NET framework symbols: http://referencesource.microsoft.com/symbols. Additionally, we tell Visual Studio that we would like to cache all downloaded symbol files in the folder C:\Zone. The caching mechanism can be a time saver to avoid downloading the same symbol’s files each time a debug session is started. Finally, we tell Visual Studio that we want the locations to be used only when the symbols are manually loaded—that is, all the configuration that is needed for Visual Studio to support source-level debugging of the .NET frameworks. Let’s give it a shot and see how easy it is. Create a simple C# console application with the following line of code in the Main method:

Console.WriteLine("Let's use SOS!");

Build the project and set a breakpoint on the preceding line of code using F9. Next, press F5 to debug the application; after the breakpoint hits, bring up the Modules window using CTRL-ALT-U. Locate the mscorlib.dll module and right-click it followed by Load Symbols. This downloads the symbols for the mscorlib.dll module that will enable source-level debugging. When the symbol has finished downloading, the Symbol Status column shows Symbols Loaded. Now, we can step into the Console.WriteLine code by pressing F11. The first thing you will notice is that an End User License Agreement (EULA) is displayed, as shown in Figure 8.

Figure 8. .NET Framework source EULA


Please take your time reading through the EULA and, if you agree to the terms, click the Accept button. The source code behind the Console.WriteLine method is now automatically downloaded and shown in the debugger, allowing you to step through the code just like you would your own code.

Please note that, at the moment, the following symbols are made available on the symbol server:

  • mscorlib.dll

  • system.dll

  • system.data.dll

  • system.drawing.dll

  • system.web.dll

  • system.web.extensions.dll

  • system.windows.forms.dll

  • system.xml.dll

  • Windows Presentation Foundation DLL’s

  • Microsoft.visualbasic.dll

Microsoft has made sure that the infrastructure behind publishing new symbols and source code is fully automatic, and we can expect to see more and more symbols and source code become available with time.

Other  
  •  System Center Configuration Manager 2007 : Creating Packages (part 3) - About Packages, Programs, Collections, Distribution Points, and Advertisements
  •  System Center Configuration Manager 2007 : Creating Packages (part 2) - Comparing GPO-based Software Distribution to ConfigMgr Software Distribution
  •  System Center Configuration Manager 2007 : Creating Packages (part 1)
  •  Microsoft Dynamic AX 2009 : Configuration and Security - Security Framework (part 3) - Security Coding
  •  Microsoft Dynamic AX 2009 : Configuration and Security - Security Framework (part 2) - Applying Security
  •  Microsoft Dynamic AX 2009 : Configuration and Security - Security Framework (part 1)
  •  Microsoft Dynamic AX 2009 : Configuration and Security - Licensing and Configuration
  •  Microsoft Dynamic AX 2009 : Configuration and Security - IntelliMorph
  •  Microsoft Dynamic AX 2009 : Reflection APIs (part 3) - Treenodes API
  •  Microsoft Dynamic AX 2009 : Reflection APIs (part 2) - Dictionary API
  •  
    Video
    Video tutorials
    - How To Install Windows 8

    - How To Install Windows Server 2012

    - How To Install Windows Server 2012 On VirtualBox

    - How To Disable Windows 8 Metro UI

    - How To Install Windows Store Apps From Windows 8 Classic Desktop

    - How To Disable Windows Update in Windows 8

    - How To Disable Windows 8 Metro UI

    - How To Add Widgets To Windows 8 Lock Screen

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010
    programming4us programming4us
    Top 10
    Free Mobile And Desktop Apps For Accessing Restricted Websites
    MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
    TOYOTA CAMRY 2; 2.5 : Camry now more comely
    KIA SORENTO 2.2CRDi : Fuel-sipping slugger
    How To Setup, Password Protect & Encrypt Wireless Internet Connection
    Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
    Backup & Restore Game Progress From Any Game With SaveGameProgress
    Generate A Facebook Timeline Cover Using A Free App
    New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
    SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
    Popular Tags
    Video Tutorail Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Exchange Server Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe Photoshop CorelDRAW X5 CorelDraw 10 windows Phone 7 windows Phone 8 Iphone