Showing posts with label Visual Studio 2008. Show all posts
Showing posts with label Visual Studio 2008. Show all posts

Wednesday, June 16, 2010

VB.NET Debug Visualizer for Guids for Visual Studio 2010

Every once in a while I must program in VB.NET. My largest frustration is how Visual Studio handles Guids while debugging VB.NET code.

Seeing "System.Guid" as the value for a variable that contains a Guid is really not helpful. Debugging in C# correctly displays the actual value in the same situation.

Visual Studio provides an avenue to rectify this issue. You can create a new class library project and replace the contents of the default class file with the below code snippet.

<Assembly: DebuggerDisplay("{ToString()}", Target:=GetType(Guid))>

Public Class EmptyGuidVisualizerClass
    ' Empty
End Class

After compiling, copy the DLL to "%USERPROFILE%\My Documents\Visual Studio 2010\Visualizers" and restart Visual Studio. The Guids should resolve to their actual values.

After installing this in Visual Studio 2010, I found that it also works in Visual Studio 2008. The DLL should, likewise, be placed in the Visualizers directory in the Visual Studio 2008 folder in My Documents.

I created a batch file that can be used to install the DLL for 2010 and 2008. The batch file and the DLL must be in the same directory.

@ECHO OFF
SET STARTDIR=%CD%

pushd .

cd "%USERPROFILE%\My Documents"

IF EXIST ".\Visual Studio 2008" (
pushd .
echo "2008 Exists!"
cd ".\Visual Studio 2008"

IF NOT EXIST ".\Visualizers" (
 echo "Creating Visualizers Directory."
 mkdir Visualizers
)

copy "%STARTDIR%\GuidVisualizer.dll" .\Visualizers

popd
)

IF EXIST ".\Visual Studio 2010" (
pushd .
echo "2010 Exists!"
cd ".\Visual Studio 2010"

IF NOT EXIST ".\Visualizers" (
 echo "Creating Visualizers Directory."
 mkdir Visualizers
)

copy "%STARTDIR%\GuidVisualizer.dll" .\Visualizers

popd
)

popd

After creating it, I googled and found someone who came up with almost the same code, http://www.michelrenaud.com/?p=7 . This blog post contains pictures if you care to see the end result. Microsoft Connect has a similar resolved issue: https://connect.microsoft.com/VisualStudio/feedback/details/89801/show-guid-value-in-debug.

Wednesday, January 28, 2009

Remote Debugging and Loading a Symbol File

While doing some exploratory SharePoint development, I ran across a peculiar situation. My development methods generally don't require a lot of remote debugging, but since I was exploring possibilities, I dove farther into it. I deployed my solution to my server, started remote debugging on the server, and attached to the w3wp worker processes.

I opened the Modules window (Ctrl+Alt+U) in Visual Studio and located my assembly. (Note: The image on the left does not contain my assembly, but is just for reference) The Symbol Status column had the phrase "Cannot find or open the PDB file." and didn't say "Symbols loaded." as I had expected. So, I tried to load the symboles by:
Right click on module -> "Load Symbols From" -> "Symbol Path"

This opened up an open file dialog. Selecting the PDB file on my hard drive produced an error about not being able to find the file. It was not immediately obvious why it couldn't find the file. After some experimentation, I discovered that the paths in the "Symbol File" column are specific to the computer being debugged and not translated by the remote debugging functionality. I had assummed that the symbol files loaded were from my local computer and not from the remote server. After I discovered this, I was able to correctly place the PDB file on the remote server, re-attach to the processes, and magicly the symbol loaded.

There isn't much information on the web on this topic, so hopefully this will save someone a headache.

Tuesday, January 27, 2009

Where Did Debug Go?

A little while ago I loaded a project into a new install of Visual Studio 2008. I didn't think about it much at the time, but the "Solution Configuration" dropdown list (the one w/ Debug/Release compile options) was disabled on the screen. I tried to do some debugging and set my breakpoints. When the debugger attached to the process it couldn't set the breakpoints; the code wasn't compiling in debug mode.

I looked at the Modules panel in VS2008 and found that the assembly had compiled with optimization "on". Apparently the last time I compiled I my project, it was in Release mode. I look at the project properties and found the settings to be that of the Release, confirming my previous thought. I looked at the top of the build properties page and there was no dropdowns to switch to a different build configuration.

I thought perhaps something in the project file was not setup correct. So I opened the project file in notepad and looked for the build options. Everything looked like it was in the correct place and further confirmed the Release mode settings.

My next place to check was in Tools -> Options. I looked in all of the options in the tree, nothing jumped out at me. I talked with my colleagues and no one knew how to fix my issue.

I turned to my friend Google and several searches after finding nothing that seemed to fix my issue I had a glimmer of hope. The forum question:

Visual Studio 2008's Build Configuration ONLY offers DEBUG build option -- where did RELEASE GO?

That was amazingly similar to what I was experiencing but I was stuck in Release mode. Awesome, I could feel the solution to my issue was at hand. I looked to find the post marked as the answer only to find disappointment. I continued reading the posts after that and found a post by InteXX which stated:

It's in Tools\Options\Projects and Solutions. Select the Show advanced build configurations checkbox and click OK.


Sweet success! I have added a screen shot to help.



I hope this post saves people time hunting around to fix this issue. There isn't much on the web pertaining to it and the option isn't very well located.