This project has moved and is read-only. For the latest updates, please go here.

dynamic scope usage broken in 2.0.4


It looks like nuget package for version 2.0.4 contains a wrong version of the dll.
Steps to replicate the issue:

1) Download 2.0.4 source code
2) Add a simple console application to ExpressionEvaluator's solution with the following code in the main method
        dynamic scope = new ExpandoObject();

        scope.FirstName = new ExpandoObject();
        scope.FirstName.Value = "Sebastiano";

        var exp = new CompiledExpression("FirstName.Value");
        var fx = exp.ScopeCompile();

3) Add ExpressionEvaluator as project reference to the newly created console application
4) Set the console application as startup project
5) Run console application
6) Observe the expression is correctly scope compiled and the application shows the value "Sebastiano" on the console
7) Remove ExpressionEvaluator project reference from the console application's references
8) Add ExpressionEvaluator as nuget package (latest stable 2.0.4) to the console application's references
9) Run the console application
10) Observe an exception is raised of type ExpressionParseException with the following additional information: Cannot resolve symbol "FirstName" at line 1 char 0

Using 2.0.3 nuget package, the console application runs correctly.
As running the application with 2.0.4 source code works, this is suggesting 2.0.4 nuget package is containing an older or faulty version.

Best regards,
Sebastiano Serri


RupertAvery wrote Mar 1, 2016 at 11:55 PM

Thanks for pointing this out. The binary version is correct, it appears I have broken some dynamics in 2.0.4.

The problem is, the Expression Eval compiler does not know what type the scope variable is. When calling ScopeCompile without generic parameters, the type is assumed to be type Object.

I tried to move away from checking if a type is dynamic by assuming it is one if it is type Object. As you have discovered, this does not work well if the scope variable is dynamic.

It is probably safe to assume that if somebody tries to access a property or method and the type is of type Object that they assume that the object is a dynamic. I am just worried if someone is just trying to call a method on object, that the Eval compiler will treat it as a dynamic call, even if it is just ToString(). Every call involving that object would also be called as dynamic.

I'll try to think of a better solution, but if this is a deal breaker for you, for now just modify IsDynamic in ExpressionHelper to also return true if expression.Type == typeof(Object)