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

UWP trouble with interpreting dynamic expressions #1231

Open
neolithos opened this issue Sep 28, 2015 · 3 comments
Open

UWP trouble with interpreting dynamic expressions #1231

neolithos opened this issue Sep 28, 2015 · 3 comments

Comments

@neolithos
Copy link

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

@jdhardy
Copy link
Member

jdhardy commented Sep 28, 2015

AFAIK IronPython had never been tested under UWP. Trying it there is
unexplored territory, although please continue to file any issues you may
find.
On Sep 28, 2015 6:40 AM, "neolithos" [email protected] wrote:

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>(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.CallSite1.CreateCustomNoMatchDelegate(MethodInfo invoke) at System.Runtime.CompilerServices.CallSite1.MakeUpdateDelegate()
at System.Runtime.CompilerServices.CallSite1.GetUpdateDelegate(T& addr) at System.Runtime.CompilerServices.CallSite1.GetUpdateDelegate()
at System.Runtime.CompilerServices.CallSite1.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.Expression1.Compile()
at TestLua.MainPage.btnClick_Click(Object sender, RoutedEventArgs e)

What is wrong?


Reply to this email directly or view it on GitHub
#1231.

@neolithos
Copy link
Author

This problem lies in the dynamic language runtime. I see that there is a project IconLanguages / dlr

Should I resubmit this issue there. Or is this here the right address?

@jdhardy
Copy link
Member

jdhardy commented Sep 28, 2015

The other one is probably better, since it's the next version of the DLR
(for IronPython 3). Unless it's a trivial fix (and it's probably not) it's
unlikely to get backported to the IronPython 2.7 branch due to backwards
compatibility.

On Mon, Sep 28, 2015 at 9:09 AM, neolithos [email protected] wrote:

This problem lies in the dynamic language runtime. I see that there is a
project IconLanguages / dlr

Should I resubmit this issue there. Or is this here the right address?


Reply to this email directly or view it on GitHub
#1231 (comment)
.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants