ASP.NET Home  Home RSS 2.0 Atom 1.0 CDF  

Manuel Abadia's ASP.NET stuff - Linq Expressions DebuggerVisualizer

 
 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.

LinqExpressionDebuggerVisualizer.zip (33.4 KB)

Update 31/08/2010:

Modified it to run on VS 2010 RTM.

LinqExpressionVisualizer_VS2010.zip (41,37 KB)

Tuesday, April 24, 2007 9:05:10 PM (Romance Daylight Time, UTC+02:00)  #    Comments [11]    |   | 
Tuesday, July 17, 2007 10:11:03 PM (Romance Daylight Time, UTC+02:00)
WOW!
great work man keep on it.
Friday, December 28, 2007 12:44:04 AM (Romance Standard Time, UTC+01:00)
could you please release an updated build. This build relies on System.Core 2.0.0.0. In visual studio 2008 the assembly is now System.Core 3.0.0.0

I would love to try it out I use expressions alot.
Friday, December 28, 2007 7:33:50 AM (Romance Standard Time, UTC+01:00)
Scott,

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

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.
Friday, January 09, 2009 2:38:56 AM (Romance Standard Time, UTC+01:00)
Dear Manuel
i get this error:

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

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

or

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.
Wednesday, June 09, 2010 5:45:47 AM (Romance Daylight Time, UTC+02:00)
Hello Manuel,

I just came across a reference to your visualizer here:
http://codebetter.com/blogs/patricksmacchia/archive/2010/06/08/vs-2010-and-expression-tree-visualization.aspx

Do you suppose you could update your code to run inside vs21010?

Cheers,
-Charles
Monday, July 05, 2010 11:10:45 PM (Romance Daylight Time, UTC+02:00)
Charles,

I have lost the source code for the Linq Expression DebuggerVisualizer!

I did a quick tests to reverse engineer it and I had it working again in VS2008, but it didn't seemed to work in VS2010 (I don't know why). I don't have more free time to spent on this at the moment, so I'm sorry for not providing a working VS2010 version.

Regards,
Manu.
Friday, August 13, 2010 1:24:12 PM (Romance Daylight Time, UTC+02:00)
Hi Manuel, the VS2010 sample, ExpressionTreeVisualizer was also not working because the DebuggerVisualizerAttribute was targeting the type Expression, instead of Expression<>. For some reason it needs concrete type for it to work in VS2010.
(From the comments in this page http://blogs.msdn.com/b/csharpfaq/archive/2009/11/19/debugging-expression-trees-in-visual-studio-2010.aspx)

Can you maybe try that see if that works, I would love to have your visualizer work in VS2010 too.
Thanks
Tuesday, August 31, 2010 11:41:20 PM (Romance Daylight Time, UTC+02:00)
Thank you very much Tedy. That did the trick. I'm adding the new expression types and I will upload a new version ASAP.
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Copyright © 2010 Manuel Abadia. All rights reserved.