Wednesday, August 29, 2007

I wish I had time to come up with more concrete information (examples/code) in this post, but I don't have the time to work that stuff up.  I did think it would be useful for people searching for solutions to this problem, so here it is in all its ambiguity.

I was playing with expression tree inspection and dynamic interpretation the other day, when I hit something that I was sure was a bug.  I was inspecting an expression tree, identifying "branches" of interest, and generating lamdba expressions from them on the fly.

You might do this to break up an expression into separate units of execution to spread across multiple processors (a la PLINQ), or to replace parts of a tree requiring local execution before passing off to another layer to be transformed into another domain like SQL, or whatever.  In any case, I was doing it.

I found that if the type of the expression was a value type, I could not create a lambda expression returning object from it, even though there is an inheritance relationship.  You get a fairly straightforward, but perhaps surprising exception.

After some back and forth with the Linq team, I discovered that this was by design.  In the case of value types, the boxing operation required to make an object must be represented by a unary convert expression. The solution is to wrap such expression trees with a call to Expression.Convert(expression, typeof(object)).

posted on Wednesday, August 29, 2007 4:17:11 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]
 Tuesday, August 28, 2007

Today is my 1-year anniversary at Microsoft.  I've been having a blast working on all kinds of crazy stuff including but not limited to:

And, Seattle has turned out to be a really fun place to live.

posted on Tuesday, August 28, 2007 9:34:52 AM (Pacific Standard Time, UTC-08:00)  #    Comments [2]
 Thursday, August 23, 2007

posted on Thursday, August 23, 2007 1:13:02 PM (Pacific Standard Time, UTC-08:00)  #    Comments [1]
 Friday, August 03, 2007

Today is my buddy Dave's birthday.  Here's a picture of him from a few weeks ago when he visited, which was a blast.  I've really missed Dave since we moved to Washington, so it was awesome that he could visit.

Luckily, Halo 3 is coming out soon, so we'll be hanging out alot more virtually.

Happy Birthday, Dave!

posted on Friday, August 03, 2007 8:47:20 AM (Pacific Standard Time, UTC-08:00)  #    Comments [1]