Visualizing GUIDs in the Visual Studio 2008 debugger

The application I’m currently developing at work makes extensive use of GUIDs.  If you’ve debugged Visual BASIC code in Visual Studio, you’ve probably noticed that it doesn’t display GUID values when watching a variables:

VS 2008 Watch Window showing a GUID as empty

Not very useful, is it?  I’ve heard that GUIDs display fine when debugging C#, but I haven’t tried (I’m lazy.)

A few weeks ago I ran into a blog that explained how to write a very basic visualizer to address this problem. Unfortunately I didn’t keep the link and have yet to remember the search text I used to get there – so somewhere somebody is not getting due credit for this post.  I’m pretty sure it was on a Microsoft blog.  Either way, I’ll update this post if I ever find it again – for now, let it just be known that I did not come up with this technique by myself. 😉

Writing the Visualizer

  1. To create the visualizer, create a new Visual BASIC Class Library and call it “GuidVisualizer” (or whatever name you prefer.)
  2. Replace the generated class declaration with this code:
    <Assembly: DebuggerDisplay("{ToString}", Target:=GetType(Guid))>
    Public Class GuidVisualizer
    
    End Class
    
  3. Compile the library

Copy and try the Visualizer DLL

  1. Copy the generated DLL to My Documents\Visual Studio 2008\Visualizers
  2. Start Visual Studio 2008.  Using the sample example as above, the GUID is now displayedGUID displayed correctly in the VS 2008 watch window

The watch window still obsesses on the “empty” if you keep expanding the value, but at least now you can see the real value.