Visual Studio 2005 added support for Debugger Visualizers. With debugger visualizers, developers can define what information (and in what form) is shown in the debugger for a specific type. There are many visualizers for various .NET types floating around. Here is a small list of the most popular ones: ASP.NET Cache, Regular Expression, XmlDocument (and other Xml related types), a powerful looking DataSet visualizer and there is even a WindowsIdentity visualizer.
I am not going to explain in details how to write your own visualizer. You can find step by step instructions on MSDN. Most existing debugger visualizers I mentionned in the previous paragraph also have home pages where you will find details on how to write your own or even source code.
I’d like to share some tricks you might find useful when writing your own visualizers:
- You can write visualizers for public (obvious!) or internal or private types. The trick for non public types is to use the Assembly Qualified Name of the type you want to visualize. For instance, BizTalk 2006’s MessageContext property is actually an internal type (see purple type name below):
DebuggerVisualizer(typeof(<type of visualizer> ), typeof(<type of visualizer source>), TargetTypeName = “Microsoft.BizTalk.Message.Interop.MessageContext_ManagedViewOfNative, Microsoft.BizTalk.Pipeline, Version=126.96.36.199, Culture=neutral, PublicKeyToken=31bf3856ad364e35”, Description = “<description>”)]
- Your visualizer code runs non JIT’ed. So make sure you do not perform too much work or it will be slow. If you do too much, the expression evaluator will time out and interrupt your visualizer with an “Expression Evaluation timed out exception”.
- Use DataGrid instead of DataGridView. I know I used a DataGridView in my visualizer, but the DataGrid is faster, especially when running non JIT’ed.
To illustrate these points, I wrote a BizTalk 2006 MessageContext debugger visualiser. You can download the complete solution BTSVisualizers.zip below. It works with Visual Studio 2005 and BizTalk 2006 only.
Load the visualizer solution in Visual Studio and build the release comfiguration.To install the MessageContext visualizer, shut down all instances of Visual Studio and copy BTSVisualizers.dll to %VS8ROOT%\Common7\Packages\Debugger\Visualizers. (If you installed Visual Studio at the default location, that would be C:\Program Files\Microsoft Visual Studio 8\Common7\Packages\Debugger\Visualizers) That’s it!
The next time you debug a pipeline (by attaching to BTSNTSVC.exe), you can hover the mouse on the “Context” variable of the message and see all entries in the message context:
Unfortunately, this visualizer will not display anything useful unless you are debugging a BizTalk artifact by attaching to BTSNTSVC.exe. This is because most debugging tools (like pipeline.exe) do not populate the message context.