Expression Tree Visualizer

Some of you may remember a rather handy ExpressionTree debugger visualizer that allowed the visualization of expressions. Basically it was extremely handy and a great way of getting to know the Expression API a bit better.

Unfortunately this was a VS2008 sample, and it does not seem to come with VS2010.

I had not been missing it as I have not been doing much with Expressions, that is until the other day, and I really started to miss it. So I set about trying to get it to work.

Here are the steps you will need to follow to get it to work

  1. Downloaded VS2008 samples from link above : http://code.msdn.microsoft.com/Visual-Studio-2008-C-d295cdba
  2. Open contained Expression Debugger Visualse project in VS2010
  3. Change the projects to target .NET4.0
  4. Change the references to point to this location for the DebuggerVisualizers.dll : C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.VisualStudio.DebuggerVisualizers.dll
  5. Add a DebuggerVisualizer assembly targeting attribute definition for each and ever subclass (and including) Expression
  6. Built the projects, checked that I can actually visualize an expression tree. All works fine in modified standalone project from samples
  7. Copied the ExpressionTreeVisualizer.dll to the following locations

    …\Documents\Visual Studio 2010\Visualizers …\Program Files\Microsoft Visual Studio 10.0\Common7\Packages\Debugger\Visualizers

Just in case you are curious about what I mean in  by Step 5 above, this is what I had to do

 [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(Expression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(BinaryExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(BlockExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(ConditionalExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(ConstantExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(DebugInfoExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(DefaultExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(DynamicExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(GotoExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(IndexExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(InvocationExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(LabelExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(LambdaExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(ListInitExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(LoopExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(MemberExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(MemberInitExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(MethodCallExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(NewArrayExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(NewExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(ParameterExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(RuntimeVariablesExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(SwitchExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(TryExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(TypeBinaryExpression), Description = "Expression Tree Visualizer")] [assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerForVisualStudio2010), typeof(ExpressionTreeVisualizerObjectSource),      Target = typeof(UnaryExpression), Description = "Expression Tree Visualizer")] 

Worked a treat and for those of you that are simply to lazy to do this work, here is zip file containing a valid VS2010 copy of a C# project that will build this Expression Debugger Visualizer for you:

http://dl.dropbox.com/u/2600965/ExpressionTreeVisualizer.zip

About these ads

One thought on “Expression Tree Visualizer

  1. Markus says:

    The same procedure also works for VS 2012 (with the folder name “Microsoft Visual Studio 10.0″ becoming “Microsoft Visual Studio 11.0″ of course).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s