Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Creating Debugger Visualizers with Visual Studio 2005 : Page 3

With debugger visualizers, you can define the information you would like to see about a specific .NET or custom class during debug mode. And as the name suggests, you can also choose how you would like to visualize these details.


advertisement
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.

// C#: DataTable dt =GetADataTable(); VisualizerDevelopmentHost dv = new VisualizerDevelopmentHost( dt, typeof(CustomDV.DTMsgBox)); dv.ShowVisualizer(); ' VB: Dim dt as DataTable=GetADataTable() Dim dv As VisualizerDevelopmentHost = New _ VisualizerDevelopmentHost(dt, _ GetType(CustomDV.DTMsgBox)) dv.ShowVisualizer()

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.



Julia Lerman is an independent consultant who has been designing and writing software applications for 20 years. She lives in Vermont where she runs the Vermont.NET User Group. Julia is well known in the .NET community as an INETA Board member, .NET MVP, ASPInsider, conference speaker, and prolific blogger. You can read Julia's blog at thedatafarm.com/blog.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date