2
Vote

Compilation "PI * R * R = AREA" expression raise Exception

description

Compilation "PI * R * R = AREA" expression raise Exception "ArithmeticElement: Operation 'Multiply' is not defined for types 'Double' and 'Decimal"
 
It it wrong because all variables (PI, R, AREA) are decimal.
 
Code to reproduce exception
 
var eContext = new ExpressionContext();
eContext.Imports.AddType(typeof(Math));
 
var words = new string[] {"PI", "R", "AREA" };
foreach (var word in words)
eContext.Variables[word] = 0m;
 
var evaluator = eContext.CompileGeneric<bool>("PI * R * R = AREA");

comments

bugmenot2 wrote Jun 9, 2012 at 11:32 AM

try to convert decimals to double
ex:
context.Variables.Add("price", (double) (item.RurPrice * item.ExchangeRate));