Skip to content
This repository was archived by the owner on Sep 14, 2018. It is now read-only.
This repository was archived by the owner on Sep 14, 2018. It is now read-only.

UWP trouble with interpreting dynamic expressions #1231

@neolithos

Description

@neolithos

Hello,

a really Q&D example for showing the issue.

First the simple callsitebinder:

private class BinaryCallSiteBinder : BinaryOperationBinder
{
    public BinaryCallSiteBinder()
        : base(ExpressionType.Add)
    {
    }

    public override DynamicMetaObject FallbackBinaryOperation(DynamicMetaObject target, DynamicMetaObject arg, DynamicMetaObject errorSuggestion)
    {

        return new DynamicMetaObject(
            Expression.Convert(
            Expression.Add(
                Expression.Convert(target.Expression, typeof(int)),
                Expression.Convert(arg.Expression, typeof(int))
            ), typeof(object)),

            BindingRestrictions.GetTypeRestriction(target.Expression, typeof(int)).Merge(
                BindingRestrictions.GetTypeRestriction(arg.Expression, typeof(int))
            ));
    }
}

And the calling code:

var expr = DynamicExpression.Dynamic(new BinaryCallSiteBinder(), typeof(object), Expression.Constant(40, typeof(object)), Expression.Constant(2, typeof(object)));
var f = Expression.Lambda<Func<object>>(expr);
var f2 = f.Compile();
textbox1.Text = f2().ToString();

If I run the code under Windows 8.1 Phone or the desktop .net framework, it works fine.

But under Windows 10 UWP I get the following exception:

System.ArgumentException wurde nicht von Benutzercode behandelt.
  HResult=-2147024809
  Message=Expression of type 'System.Object' cannot be used for parameter of type 'System.Runtime.CompilerServices.CallSite' of method 'Boolean SetNotMatched(System.Runtime.CompilerServices.CallSite)'
  Source=System.Linq.Expressions
  StackTrace:
       at System.Dynamic.Utils.ExpressionUtils.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arg, ParameterInfo pi)
       at System.Linq.Expressions.Expression.Call(MethodInfo method, Expression arg0)
       at System.Runtime.CompilerServices.CallSite`1.CreateCustomNoMatchDelegate(MethodInfo invoke)
       at System.Runtime.CompilerServices.CallSite`1.MakeUpdateDelegate()
       at System.Runtime.CompilerServices.CallSite`1.GetUpdateDelegate(T& addr)
       at System.Runtime.CompilerServices.CallSite`1.GetUpdateDelegate()
       at System.Runtime.CompilerServices.CallSite`1.Create(CallSiteBinder binder)
       at System.Runtime.CompilerServices.CallSite.Create(Type delegateType, CallSiteBinder binder)
       at System.Linq.Expressions.DynamicExpression.Reduce()
       at System.Linq.Expressions.Interpreter.LightCompiler.CompileNoLabelPush(Expression expr)
       at System.Linq.Expressions.Interpreter.LightCompiler.Compile(Expression expr)
       at System.Linq.Expressions.Interpreter.LightCompiler.CompileTop(LambdaExpression node)
       at System.Linq.Expressions.Expression`1.Compile()
       at TestLua.MainPage.btnClick_Click(Object sender, RoutedEventArgs e)

What is wrong?

Same Issue IronLanguages/dlr#3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions