Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParseException with Expressions containing Convert method #401

Open
kyleherzog opened this issue Jul 17, 2020 · 3 comments
Open

ParseException with Expressions containing Convert method #401

kyleherzog opened this issue Jul 17, 2020 · 3 comments
Assignees

Comments

@kyleherzog
Copy link

@kyleherzog kyleherzog commented Jul 17, 2020

I'm trying to take expressions created on a client, convert them to string by calling ToString, pass the string values to a web endpoint, and then convert them back to expression objects using DynamicExpressionParser.ParseLambda. In most cases this works. However, if i have an expression that results in a Convert method being called, I get the following exception.

System.Linq.Dynamic.Core.Exceptions.ParseException: '.' or '(' or string literal expected

The following simplified test case exhibits the issue.

Expression<Func<byte, bool>> originalExpression = x => x == 1;
var expressionText = originalExpression.ToString();
Console.WriteLine(expressionText);
// Output: x => (Convert(x, Int32) == 1)
var expression = DynamicExpressionParser.ParseLambda<long, bool>(new ParsingConfig(), false, expressionText);
@JonathanMagnan JonathanMagnan self-assigned this Jul 20, 2020
@JonathanMagnan
Copy link
Member

@JonathanMagnan JonathanMagnan commented Jul 20, 2020

Hello @kyleherzog ,

Thank you for reporting, we will look at it.

Best Regards,

Jon


Performance Libraries
context.BulkInsert(list, options => options.BatchSize = 1000);
Entity Framework ExtensionsEntity Framework ClassicBulk OperationsDapper Plus

Runtime Evaluation
Eval.Execute("x + y", new {x = 1, y = 2}); // return 3
C# Eval FunctionSQL Eval Function

@JonathanMagnan
Copy link
Member

@JonathanMagnan JonathanMagnan commented Jul 20, 2020

Hello @kyleherzog ,

We checked at your issue and I don't think we will support your scenario for now.

What you are currently providing is not an expression, but a string representation which is not exactly a lambda expression.

For example, the following lambda expression working:

var lambdaExpression = "x => Convert.ToInt32(x) == 1";
var expression = DynamicExpressionParser.ParseLambda<long, bool>(new ParsingConfig(), false, lambdaExpression);
var r1 = expression.Compile()(1);

But in your case, the expression string shows the following convert as Convert(x, Int32) which is not valid.

Let me know if that explains correctly why that's currently not working.

Best Regards,

Jon

@StefH
Copy link
Collaborator

@StefH StefH commented Jul 23, 2020

@kyleherzog
Maybe this library https://github.com/esskar/Serialize.Linq can help you when you want to serialize / deserialize linq.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.