Open
Description
The following statement will report an error.
using Newtonsoft.Json.Linq;
static void Main(string[] args)
{
var context = new EvalContext();
context.RegisterType(typeof(JArray));
context.Execute(@"new JArray().Contains(""D"")");
}
The error is as follows
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 12 near ".Contains(\"D\")".
Source=Z.Expressions.Eval
StackTrace:
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 66
此异常最初是在此调用堆栈中引发的:
[外部代码]
SomeTest.Program.Main(string[]) (位于 Program.cs 中)
JArray.Contains(JToken T)
only accepts JToken
, so EvalContext considers No applicable member
But we know that Newtonsoft.Json.Linq
defines implicit type conversion from String to JToken, and this statement works properly in VS.
Metadata
Metadata
Assignees
Labels
No labels