Debugging the Debugger
You can debug your custom debugger visualizer from within another project. The VisualizerDevelopmentHost class in the Microsoft.VisualStudio.DebuggerVisualizers namespace allows you to invoke the debugger visualizer programmatically without having to go through the DataTip to access it. This means you have a hook into your visualizer class and can debug into the project.
Note that an invoked debugger visualizer will run in the compiled application, just like any other class, regardless of whether it is compiled in Debug or Release mode. Therefore it is important that you consider the potential problem of accidentally deploying code with an active visualizer built in, because your end users will, indeed, see the visualizer. It may be more prudent to build a separate testing UI to debug your visualizers.
Here are the steps to debug a debugger visualizer.
- Load the project for your custom visualizer into the solution for your Windows Form application.
- Add a reference to the debugger visualizer project to the Windows Form project.
- Add a reference to Microsoft.VisualStudio.DebuggerVisualizers in the Windows Form project.
At the point in your code that the DataTable has been populated, add the following code to invoke the Debugger Visualizer class passing in the DataTable object and a type reference to visualizer.
DataTable dt =GetADataTable();
VisualizerDevelopmentHost dv =
Dim dt as DataTable=GetADataTable()
Dim dv As VisualizerDevelopmentHost = New _
Because of the possibility that you might accidentally deploy code with your debugging tool built into it, you may consider creating separate tools for invoking and debugging your visualizer debuggers.
Deploying a Custom Debugger Visualizer
Debugger visualizers get stored in a specific place on the developer's computer. Build your project in Release mode. Then in Windows Explorer, locate the DLL that you have created and copy it to My Documents\Visual Studio\Visualizers
. Note that if you have not yet used the out-of-the-box debugger visualizers, you will have to create the Visualizers folder. Also, this location has changed over a number of releases of the Visual Studio 2005 CTPs and Beta, so watch for the chance of it moving again in future releases.
Once the assembly exists in this folder, your custom debugger visualizer becomes part of your Visual Studio 2005 debugging environment. Naturally, you can share your custom debugger visualizers with other developers by distributing the assemblies.
With all that is new and exciting about Visual Studio 2005 and .NET Framework 2.0, this fantastic new feature, one of a number of great additions to Diagnostics in the .NET Framework, has been sorely overlooked so far. As more and more developers realize the beauty of this class, watch the community space for custom visualizers that other developers have written.