The binary operator Multiply is not defined for the types 'System.Int32' and 'System.Double'.

Viewed 5582

Why the following code throws an exception at runtime, whereas doing it in the traditional way compiles without problem?

var left = Expression.Constant(25d);
var right = Expression.Constant(20);

// Throws an InvalidOperationException!
var multiplyExpression = Expression.Multiply(left, right); 

var multiply = 25d * 20;
Debug.WriteLine(multiply.ToString()); // Works normally!

I won't use Expression.Convert since I can't determine exactly which expression should be converted.

4 Answers
Related