Welcome to EMC Consulting Blogs Sign in | Join | Help

Howard van Rooijen's EMC Consulting Blog (2004 - 2010)

This blog has now moved to http://howard.vanrooijen.co.uk/blog - please update your subscriptions if you wish to receive new content.

Lithium XML Debugger Visualizer for Visual Studio 2005

This post has been superseded by the following post: Conchango Xml Visualizer for Visual Studio 2005 (RTM)

Updated 06/11/2006: If you are trying to locate the Netron Project see my post "What happened to the Netron Project?"

About a month ago, I stumbled across Scott Nonnenberg's article “Debugger Visualizers on VS 2005 Community Tech Preview”, I was quite intrigued by this article and thought that Debugger Visualizers were a great addition to VS 2005 and an exciting extensibility point. On a previous project, we used the VS 2003 DataSet Visualizer extensively and I had been thinking about trying to create something akin for viewing business entities – but in VS 2003 I just couldn’t get access to the data I wanted.

In mid-March I mentioned the idea of using the Netron Library to visualize XML messages and how I’d wanted to create a VS 2005 Debugger Visualizer to Francois – his reply was that he had already finished work on a Tree-Layout diagram control called Lithium and would I like to “beta” it for him.

How it works:

The solution contains two projects – Conchango.XmlVisualizer (this is the VS 2005 visualizer) and Conchango.XmlVisualizer.Demo (this is the test harness). Conchango.XmlVisualizer contains all the interesting code;

Visualizer is invoked by the IDE when the user selects “Lithium Xml Visualizer” from the dynamic debugger drop down – it creates a modal window and launches MainForm (which contains the Lithium Control) passing in IVisualizerObjectProvider.

On the Debugee side, inside MainForm, IVisualizerObjectProvider.UpdateObject(Stream fromVisualizer, Stream toVisualizer) is called which invokes XmlVisualizerSource.TransferData(object o, Stream fromVisualizer, Stream toVisualizer). o is the object you selected in the IDE to visualize. Inside TransferData o is tested to see if it is an XmlDocument – if it is, the OuterXml is extracted and binary serlialized into a stream and pumped back out of the method using the toVisualizer stream.

The stream is then deserialized back into an XmlDocument (using the LoadXml() method) on the Debugger side and then the node structure is parsed and converted in shape nodes inside the Lithium Control.

Having to extract the XML from XmlDocument.OuterXml seems idiosyncratic – until you get your head around the fact that the XmlDocument type cannot be serialized (it’s not just Xml – there is a lot of state data held inside the object), so we have to extract the raw Xml and then work with that instead.
 
The AssemblyInfo.cs file contains the DebuggerVisualizer attribute that ties this all together:

[assembly: DebuggerVisualizer(typeof(Conchango.XMLVisualizer.XmlVisualizerSource), typeof(Conchango.XMLVisualizer.Visualizer), 0, Target = typeof(System.Xml.XmlDocument), Description = "Lithium XML Visualizer")]

DebuggerVisualizer(typeof(Conchango.XMLVisualizer.XmlVisualizerSource), typeof(Conchango.XMLVisualizer.Visualizer), 0, Target = typeof(System.Xml.XmlDocument), Description = "Lithium XML Visualizer")]

This defines what type the VisualizerSource and Visualizer are, what data type should the visualizer be associated with and what the visualizer is called.

The Conchango.XmlVisualizer project uses a post-build event to copy the build output (Conchango.XmlVisualizer.dll and Lithium.dll) to the Visual Studio Visualizer directory - %USERPROFILE%\My Documents\Visual Studio\Visualizers\

Testing the Visualizer:

  • Check that a breakpoint has been set on Conchango.XmlVisualizer.Demo.Program.cs line 56
  • Run the solution – Conchango.XmlVisualizer.Demo should load and hit the breakpoint above
  • Hover your mouse over the doc object - a dynamic DataTip should appear – click the spyglass icon – a dropdown should appear with an entry called “Lithium Xmll Visualizer”. Select this.
Data Tip

 

Now the Lithium XmlVisualizer should launch:

Lithium XmlVisualizer window

 

There is one warning attached to this visualizer – trying to visualize large Xml structures will turn VS 2005 to treacle and may hang that instance.

The sample XML file in the demo project is a small extract from The Public Whip – a UK site that has lots of interesting raw data about MPs, constituencies and other Parliamentary information – a much more interesting test data source than Northwinds…

I've created a new ProjectDistributor workspace for the project. You can download the source here.

 

Published Monday, April 11, 2005 9:22 AM by howard.vanrooijen

Comments

 

TrackBack said:

Howard Van Rooijen recently emailed me about the XML Debugger Visualizer he's developing, wondering about...
April 14, 2005 10:40 PM
 

TrackBack said:

About a month ago, I stumbled across Scott Nonnenberg's article “Debugger Visualizers on VS 2005 Community Tech Preview”, I was quite intrigued by this article and thought that Debugger Visualizers were a great addition to VS 2005 and an exciting extensibility point...
April 14, 2005 11:42 PM
 

TrackBack said:

April 22, 2005 9:44 AM
 

Howard van Rooijen's Blog said:

I released the first version of this tool back in April - and have spent a couple of days this week working...
November 24, 2005 7:10 PM
 

Howard van Rooijen's Blog said:

I released the first version of this tool back in April - and have spent a couple of days this week working...
November 24, 2005 7:10 PM
 

Howard van Rooijen's Blog said:

I released the first version of this tool back in April - and have spent a couple of days this week working...
January 29, 2006 10:16 PM
 

Yitzhak Gootvilig's Blog said:

March 21, 2006 7:07 AM
 

Yitzhak Gootvilig's Blog said:

July 18, 2006 6:47 AM
 

Howard van Rooijen's Blog said:

I released the first version of this tool back in April - and have spent a couple of days this week working
November 6, 2006 4:28 PM
 

Howard van Rooijen's Blog said:

I've updated my Lithium based XMLVisualizer for Visual Studio 2005 Beta 2. You can download the updated
November 6, 2006 4:29 PM
New Comments to this post are disabled

This Blog

Syndication

News

This blog has now moved - please visit http://howard.vanrooijen.co.uk/blog for new content!
Add to Live.com
Powered by Community Server (Personal Edition), by Telligent Systems