VB.NET Meets the DebuggerDisplay Attribute in VS2008

One of the most annoying things I find about working with the Guid class is that in order to see what the value is you have to go into a watch window and query myguid.tostring(), this doesn’t sound like too much work but if you are used to relying on datatips it can quickly be quite annoying.  For a while I’ve thought about writing a debugger visualiser or type proxy to add my own datatip for the Guid class and today I got off my backside and did it…..

The steps for doing this are relatively simple:

  • New Project (VB.NET or C#, doesn’t really matter – at this stage anyhow)
  • Add Reference: C:Program FilesMicrosoft Visual Studio 8.0Common7IDEPublicAssembliesMicrosoft.VisualStudio.DebuggerVisualizers.dll
  • Add the following attribute to any code file (most likely assemblyinfo.vb)
  • Imports Microsoft.VisualStudio.DebuggerVisualizers
    <Assembly: DebuggerDisplay(“Guid {ToString()}”, Target:=GetType(Guid))>

Now build this assembly and drop it into DocumentsVisual Studio 2005Visualizers.  Open up a new instance of Visual Studio, open an existing or new project that uses the Guid class.  Run the project with a breakpoint set so you have an instance of a Guid that you can mouse over:

image

And hey presto you have a useful datatip for the Guid class…… WRONG.  What you see here is the datatip in Visual Studio 2008 for VB.NET.  In Visual Studio 2005 this only seems to work properly for C#, VB.NET doesn’t seem to properly support the DebuggerDisplay attribute (Note you can still follow the above steps in either VB.NET or C# to create the implementing assembly, it’s just the executing code that needs to be in C# in VS2005). 

Leave a comment