Blog Home  Home Feed your aggregator (RSS 2.0)  
Linq Expressions DebuggerVisualizer - Manuel Abadia's ASP.NET stuff
# Tuesday, April 24, 2007

I have been playing a bit with Visual Studio "Orcas" Beta 1 and I really wanted to see the Expression Trees generated by Linq, so it was a good chance to play with my StructsViz component. In a couple of hours I got this DebuggerVisualizer working.

For the following expressions:

Expression<Func<Person, bool>> expr1;

Expression<Func<int, string, bool>> expr2;


expr1 = p => p.Name == "Manu";

expr2 = (idx, str) => !((idx <= 0) || (str.Length > 2));


The visualizer renders the following:

The nodes in red are terminal expressions (constants or parameters), the nodes in green are objects used by the expression subtree, and the other expression nodes are blue. The properties and fields for each node are loaded on demand and can be inspected when the node is expanded.

As expression trees are used to do really cool things I have made a free special version of StructsViz with only the functionaly needed to display expression trees. Due to the crappy NVidia drivers for Vista I haven't been able to test it extensively (as my hard disk stops from time to time, specially with Virtual PC) so let me know if there is any problem. As always, feedback is welcome.

To read more about Linq take a look at this article or at ScottGu's excellent posts about Linq.

To use the DebuggerVisualizer, create a Visualizers folder inside C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008, and copy the LinqExpressionVisualizer.dll there.

Another option is to copy the visualizer to C:\Program FIles\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\Visualizers

Please do not distribute the visualizer from your web page. Link to this page instead.

Update 13/01/2008:

Modified it to run on VS 2008 RTM. (33.4 KB)

Update 21/11/2010:

Modified it to run on VS 2010 RTM. (40,22 KB)

Tuesday, April 24, 2007 2:05:10 PM (Romance Daylight Time, UTC+02:00)  #    Comments [7]   Linq | Microsoft .NET Framework  | 
Tuesday, July 17, 2007 3:11:03 PM (Romance Daylight Time, UTC+02:00)
great work man keep on it.
Thursday, December 27, 2007 4:44:04 PM (Romance Standard Time, UTC+01:00)
could you please release an updated build. This build relies on System.Core In visual studio 2008 the assembly is now System.Core

I would love to try it out I use expressions alot.
Thursday, December 27, 2007 11:33:50 PM (Romance Standard Time, UTC+01:00)

I was wanting to update it since VS 2008 RTM was released. I'll see if I can do it soon.
Wednesday, January 7, 2009 6:03:52 PM (Romance Standard Time, UTC+01:00)
dear Manuel
how can i use it with VS 2008 team system now? is there a help?
Wednesday, January 7, 2009 11:26:10 PM (Romance Standard Time, UTC+01:00)

I thought that it also worked in VS2008 team system using the "default instructions". However, I do not have access to VS 2008 team system to test so you're on your own.
Thursday, January 8, 2009 6:38:56 PM (Romance Standard Time, UTC+01:00)
Dear Manuel
i get this error:

Unable to cast object of type 'CustomExceptionDataHolder' to type 'CustomExceptionDataHolder'.
Saturday, January 10, 2009 9:30:53 AM (Romance Standard Time, UTC+01:00)

Its really difficult to solve this without having access to VS2008 team system. However, errors like Unable to cast object of type 'XXX' to type 'XXX' are usually because two similar assemblies that contain the type XXX are loaded in memory at the same time so a cast like:

CustomExceptionDataHolder cedh = (CustomExceptionDataHolder)obj;

fails because the cast is ambiguos (CustomExceptionDataHolder is found in two assemblies)

So, my only guess is that you have multiple copies of the DebuggerVisualizer in your system. Remember that you do not have to reference it in your project. Just copy it to:

My Documents\Visual Studio 2008


C:\Program FIles\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\Visualizers

If it still failing try to delete it from there and install it into the GAC.
All comments require the approval of the site owner before being displayed.
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

[Captcha]Enter the code shown (prevents robots):

Live Comment Preview
Copyright © 2019 Manuel Abadia. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.