zzzprojects / Eval-Expression.NET

C# Eval Expression | Evaluate, Compile, and Execute C# code and expression at runtime.
https://eval-expression.net/
Other
449 stars 86 forks source link

Incorrect number of arguments supplied for lambda invocation #110

Closed cesaryuan closed 3 years ago

cesaryuan commented 3 years ago

The Program below throws an error, but it shouldn't.

public delegate int Del(params int[] param);

public int sum(params int[] param)
{
    return param.Sum();
}

void Main()
{
    var context = new EvalContext();
    Del fun = new Del(sum);

    Console.WriteLine(fun(1, 2));
    Console.WriteLine(context.Execute("fun(1, 2)", new {fun=fun}));
}

Error Message throwed

Incorrect number of arguments supplied for lambda invocation
JonathanMagnan commented 3 years ago

Hello @cesaryuan ,

Thank you for reporting,

We indeed can reproduce this issue with your code. We will look at it.

Best Regards,

Jon

JonathanMagnan commented 3 years ago

Hello @cesaryuan ,

The v4.0.51 has been released.

Could you test it and let us know if we fixed it successfully?

cesaryuan commented 3 years ago

Thank you so much! It has worked!

cesaryuan commented 3 years ago

When I change the statements as follows, another Exception is throwed.

public delegate int Del(params int[] param);

public int sum(params int[] param)
{
    return param.Sum();
}

void Main()
{
    var context = new EvalContext();
    Del fun = new Del(sum);
    Console.WriteLine(fun(new[] { 1, 2}));
    Console.WriteLine(context.Execute(@"fun(new[] { 1, 2})", new {fun=fun}));
}

Exception:

No coercion operator is defined between types 'System.Int32[]' and 'System.Int32'.
JonathanMagnan commented 3 years ago

Hello @cesaryuan ,

Unfortunately, that issue is a lot harder on our side to fix as it requires a big revamps to use some existing code about method resolution.

It is possible to know if you have a license for our library? If yes, could you sent your license name to confirm it at: info@zzzprojects.com

If you have paid for the support, we will try to give this issue another shot.

Best Regards,

Jon

JonathanMagnan commented 3 years ago

Hello @cesaryuan ,

We got an email confirming it.

I cannot promise anything yet since that one is more complex but we will look at it again and try to support this case.

Best Regards,

Jon

cesaryuan commented 3 years ago

Hello @cesaryuan ,

We got an email confirming it.

I cannot promise anything yet since that one is more complex but we will look at it again and try to support this case.

Best Regards,

Jon

Thank you for your effort!

JonathanMagnan commented 3 years ago

Hello @cesaryuan ,

The v4.0.53 has been released.

We did a quick fix as we didn't succeed to plug the resolution we normally use for methods. So we might still have some improvement to do here but it should now work with your case without a problem.

Best Regards,

Jon