Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UWP trouble with interpreting dynamic expressions #3

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

UWP trouble with interpreting dynamic expressions #3

neolithos opened this issue Sep 28, 2015 · 9 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/main#1231

@neolithos
Copy link
Author

Is there a way to help to find the problem?

It would be nice if my library runs on UWP, to port my application to Windows 10 IoT.

@neolithos
Copy link
Author

The Delegate that is generated for the expression is Func<object,object,object,object> but in a later stage Func<CallSite,object,object,object> is expected.

https://github.com/dotnet/corefx/blob/master/src/System.Dynamic.Runtime/src/System/Linq/Expressions/Compiler/TypeInfoExtensions.cs

But CallSiteOps.SetNotMatched expects a CallSite as first argument (see CallSite<>.MakeUpdateDelegate). Btw. marked as "Do not use"?

I do not understand, who is the right address. I am little confused about all the implementations.

Is this here know the right place? Because, now this problem is a real show stopper for updating to W10.

@jdhardy
Copy link
Member

jdhardy commented Sep 30, 2015

It depends on whether it's an issue in how IronPython uses the DLR, or if
the DLR implementation changed. To be honest, I'm not entirely clear on the
relationship between all of the various .NET runtimes any more. I do know
that it works as a desktop app on Windows 10/.NET 4.6 (as that's where I do
my development) but I don't know what variant of the runtime UWP apps use.

On Wed, Sep 30, 2015 at 2:39 AM, neolithos [email protected] wrote:

The Delegate that is generated for the expression is Func but in a later
stage Func is expected.

https://github.com/dotnet/corefx/blob/master/src/System.Dynamic.Runtime/src/System/Linq/Expressions/Compiler/TypeInfoExtensions.cs

But CallSiteOps.SetNotMatched expects a CallSite as first argument (see
CallSite<>.MakeUpdateDelegate). Btw. marked as "Do not use"?

I do not understand, who is the right address. I am little confused about
all the implementations.

Is this here know the right place? Because, now this problem is a real
show stopper for updating to W10.


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

@neolithos
Copy link
Author

IronPython and NeoLua are using the same parts of the dynamic runtime (I do not know the current version as good as previous).
I will repost this issue in the corefx project, because that is used by W10 UWP.

In .net core the dynamic stuff is interpreted and not compiled anymore. I have no idea how this perform.

@slide
Copy link
Contributor

slide commented Nov 13, 2016

Was this ever resolved?

@neolithos
Copy link
Author

This issue was a show stopper. So, we did go back to the old devices and libs.

I tried the code again. And it still fails. Under Win10 1607 even harder. After putting the code in a try catch block I get the same exception.

So, it seems not resolved.

@woachk
Copy link

woachk commented Jun 5, 2018

Windows 10 UWP uses an Ahead-of-time compiler toolset without a JIT, so do not even try. (Reflection alone is already painful enough)

Debug builds uses a JIT though, but you’ll never get it working for release.

@DjArt
Copy link

DjArt commented Mar 18, 2019

Works!
#179

@neolithos
Copy link
Author

Cool! Thx.

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

No branches or pull requests

5 participants