zzzprojects / Eval-Expression.NET

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

No applicable member has been found for ".GetType()" #100

Closed cesaryuan closed 3 years ago

cesaryuan commented 3 years ago

I think all class instances have a GetType() method, but EvalContext tells me that this is not the case. The code is as follows:

var context = new EvalContext();
context.RegisterType(typeof(JObject));
var aa = context.Execute(@"JObject.Parse(""{}"").SelectTokens(@""$.*"").GetType();");

It throws this error,

Z.Expressions.Compiler.Shared.EvalException
  HResult=0x80131500
  Message=Oops! No applicable member has been found for the expression. The error occurred for expression "." at position 40 near ".GetType();".
  Source=Z.Expressions.Eval
  StackTrace:
   at .(ExpressionScope , Expression , Type , String , List`1 , SyntaxNode , List`1 , Boolean )
   at .(ExpressionScope , Expression , Type , String , List`1 , Boolean , List`1 , SyntaxNode , Expression& )
   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 SomeTest.Program.Main(String[] args) in E:\Desktop\Program\C#\SomeTest\Program.cs:line 58

  此异常最初是在此调用堆栈中引发的: 
    [外部代码]
    SomeTest.Program.Main(string[]) (位于 Program.cs 中)

However, in fact it shouldn’t throw an error, it should be working properly.

JonathanMagnan commented 3 years ago

Hello @cesaryuan ,

Thank you for reporting, we will look at it.

A fix has been done and will be deployed tomorrow if the code is accepted.

Best Regards,

Jon

JonathanMagnan commented 3 years ago

Hello @cesaryuan ,

The v4.0.38 has been released.

Let me know if everything works as expected.

cesaryuan commented 3 years ago

Tested it. Works great!