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

GenericArguments[0], 'System.String', on 'System.Nullable`1[T]' violates the constraint of type 'T'. #112

Closed cesaryuan closed 3 years ago

cesaryuan commented 3 years ago

Execute the following statement by EvalContext throws an error, could you please check it out?

var list = new List<string>() { "test"};
Console.WriteLine(list?[0]);

Error Message throwed


GenericArguments[0], 'System.String', on 'System.Nullable`1[T]' violates the constraint of type 'T'.

  at System.RuntimeType.ValidateGenericArguments(MemberInfo definition, RuntimeType[] genericArguments, Exception e)
   at System.RuntimeType.MakeGenericType(Type[] instantiation)
   at .(ExpressionScope , SyntaxNode , Expression , Boolean )
   at .(ExpressionScope , SyntaxNode )
   at .(ExpressionScope , SyntaxNode , Type , Expression , List`1 )
   at .(ExpressionScope , SyntaxNode , Expression , Boolean )
   at .(ExpressionScope , SyntaxNode , Expression , Boolean )
   at .(ExpressionScope , SyntaxNode , Expression , Boolean )
   at Z.Expressions.CodeCompiler.CSharp.ExpressionParser.ParseSyntax(ExpressionScope scope, SyntaxNode node, Type resultType)
   at .[](EvalContext , String , IDictionary`2 , Type , EvalCompilerParameterKind , ExpressionScope , String , Boolean , Boolean )
   at .[](EvalContext , String , IDictionary`2 , Type , EvalCompilerParameterKind , Boolean , Boolean , Boolean )
   at Z.Expressions.EvalContext.Execute[TResult](String code)
   at Z.Expressions.EvalContext.Execute(String code)
   at UserQuery.Main(), line 14

Incorrect number of arguments supplied for lambda invocation

JonathanMagnan commented 3 years ago

Hello @cesaryuan ,

Thank you for reporting, 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!