Cannot convert to System.Expressions.Expression type ?

Hi All!

While i was hacking into linq and played around with expression trees i wondered why the underneath expression cannot be converted to a System.Expression. Is there someone who can enlight me It kinda looks buggy to me. Especially when
the Expression<Func<bool,bool>> ok = param1 => param1 == false; is converted without any error at all. Only chaning the true into false raises the error.



Func
<bool,bool> f1 = p1 => true;
Func<bool,bool> f2 = p2 => p2 == true;
Expression<Func<bool,bool>> ok = param1 => param1 == false; //Ok!
Expression<Func<bool,bool>> error = param1 => param1 == true; //Compile error

 


IT gives me the error

Error 1 The expression contains operations that cannot be translated to a System.Expressions.Expression

Any ideas on this
Regards,

Emile

UPDATE: Even stranger if you use MS samples on DLINQ (Sample3)

var q = from p in db.Products where p.UnitsInStock <= p.ReorderLevel && p.Discontinued == false select p;

Changes into

var q = from p in db.Products where p.UnitsInStock <= p.ReorderLevel && p.Discontinued == true select p;

It doesnt seem to compile anymore, but doing

var q = from p in db.Products where p.UnitsInStock <= p.ReorderLevel && p.Discontinued select p;

seems to work



Answer this question

Cannot convert to System.Expressions.Expression type ?

  • Timo van Noppen

    Thanks for pointing to this issue.

    This is an issue with the preview compiler. It has to do with how the current internal representation of C# code lines up with the new experimental expression tree generation. It is not easy to fix in a "shallow" way, so you're probably not going to see it mended until the "real" (product) compiler revs up to deal with LINQ.

    Luckily you have a workaround right there (since comparing with true is redundant except for readability), so hopefully you or others don't get blocked on it.

    Thanks again!

    Mads

  • Cannot convert to System.Expressions.Expression type ?