Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Visual Studio 2013 and .NET 4.5 Expert Cookbook

You're reading from   Visual Studio 2013 and .NET 4.5 Expert Cookbook Over 30 recipes to successfully mix the powerful capabilities of Visual Studio 2013 with .NET 4.5

Arrow left icon
Product type Paperback
Published in Sep 2014
Publisher
ISBN-13 9781849689724
Length 308 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Abhishek Sur Abhishek Sur
Author Profile Icon Abhishek Sur
Abhishek Sur
Arrow right icon
View More author details
Toc

Table of Contents (9) Chapters Close

Preface 1. A Guide to Debugging with Visual Studio FREE CHAPTER 2. Enhancements to WCF 4.5 3. Building a Touch-sensitive Device Application Using Windows Phone 8 4. Working with Team Foundation Server 5. Testing Applications Using Visual Studio 2013 6. Extending the Visual Studio IDE 7. Understanding Cloud Computing with Windows Azure Index

Debugging a .NET program using the framework library source

The .NET library source code has already been released. This gives you a chance to locate and debug the actual source code that has been used to build the library that you are using. This is very useful as the code that has been downloaded from the server will contain a lot of comments, which will help you with the internals of the library that we are using.

How to do it…

Source code debugging is another technique for .NET library debugging. Let's take a look at how you can use Visual Studio to step into Microsoft Source for the .NET library:

  1. To debug your code with the .NET library source code, you first need to go to Tools | Options and then navigate to Debugging | General.
  2. Turn off Enable Just My Code.
  3. Turn on Enable source server support, as shown in the following screenshot:
    How to do it…
  4. Now, in the Symbols tab of the window, you need to specify the cache server location where it can get the program debug information.
  5. Set the symbol file location to http://referencesource.microsoft.com/symbols.
  6. Set the cache location where the symbols will get downloaded as soon as you use it during debugging. You need to make sure that the location is accessible from your user account.
  7. You can select a list of options for which the reference server will be connected to the symbols. For best results, we should select the modules that you need to load symbols to.
  8. You can also load all the symbols once at this time and use them during debugging.
  9. You can now start debugging.

How it works…

Microsoft actually maintains a number of servers that hold static files. These files are available based on the checksum. Once the symbols are loaded onto your machine, the reference server can be used to download the appropriate source file directly while you are debugging your application and press Step Into to a method that is defined in the .NET class library. As we already know, a program database (PDB) file holds all the information about line numbers, location, and even the checksum of the file. Visual Studio invokes a request to a file by sending this information available in the symbol files and downloads the appropriate file.

Let's start our sample application and place a breakpoint in the first line of the code. Now run the project until the breakpoint is hit. Open Call Stack, right-click on MSCorlib, and select Load Symbols. This will download the symbols of MScorlib, which will take a considerable amount of time. Once the symbols are downloaded, you can start debugging your application.

You can see that when the download is complete, the Call Stack frames turn dark because all the line numbers are now available. Now you can press F11 to step into the library code, say, for instance, Console.WriteLine.

You will be prompted with a license agreement when you choose Call Stack for the first time. You can even use Call Stack to move back and forth to different call statements.

Tip

You cannot evaluate some of the variables and values while debugging as .NET bits that are shipped with the .NET framework are built in the optimized mode. Putting a break just above the line can show the content of the code.

Don't expect the source of all .NET dlls to be available. Most of the dlls are already made available and as time goes, it will increase the numbers. If you see that Load Symbols is disabled or the PDB isn't loading, then you should consider that the dll is not available.

You have been reading a chapter from
Visual Studio 2013 and .NET 4.5 Expert Cookbook
Published in: Sep 2014
Publisher:
ISBN-13: 9781849689724
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime