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

something wrong with the try...catch... #89

Closed cesaryuan closed 3 years ago

cesaryuan commented 3 years ago
var context = new EvalContext();
var test1 = context.Execute(@"
    var test = 1;
    try
    {
        test = 2;
    }
    catch { };");

It throw the error like this:

在 System.Linq.Expressions.Expression.ValidateTryAndCatchHaveSameType(Type type, Expression tryBody, ReadOnlyCollection`1 handlers)
在 System.Linq.Expressions.Expression.MakeTry(Type type, Expression body, Expression finally, Expression fault, IEnumerable`1 handlers)
在 System.Linq.Expressions.Expression.TryCatch(Expression body, CatchBlock[] handlers)
在 .(ExpressionScope , SyntaxNode , Expression , Boolean )
在 .(ExpressionScope , SyntaxNode , Expression , Boolean )
在 Z.Expressions.CodeCompiler.CSharp.ExpressionParser.ParseSyntax(ExpressionScope scope, SyntaxNode node, Type resultType)
在 .[](EvalContext , String , IDictionary`2 , Type , EvalCompilerParameterKind , ExpressionScope , String , Boolean , Boolean )
在 .[](EvalContext , String , IDictionary`2 , Type , EvalCompilerParameterKind , Boolean , Boolean , Boolean )
在 Z.Expressions.EvalContext.Execute[TResult](String code)
在 Z.Expressions.EvalContext.Execute(String code)
在 SomeTest.Program.Main(String[] args) 在 E:\Desktop\Program\C#\SomeTest\Program.cs 中: 第 18 行
catch 体与 try 体的类型必须相同
The type of the catch body and the try body must be the same
JonathanMagnan commented 3 years ago

Thank you for reporting @cesaryuan ,

We will look at how we can fix this issue

Best Regards,

Jon

JonathanMagnan commented 3 years ago

Hello @cesaryuan,

The v4.0.27 has been released.

Could you try the latest version and let me know if my developer correctly fixed your issue?

Best Regards,

Jon

cesaryuan commented 3 years ago

@JonathanMagnan Thanks, it works for me. 👍