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

System.Linq.Dynamic.Core.Exceptions.ParseException : No applicable method 'DateTime' exists in type #662

Closed
ascott18 opened this issue Jan 13, 2023 · 4 comments
Assignees
Labels

Comments

@ascott18
Copy link
Contributor

ascott18 commented Jan 13, 2023

1. Description

I am unable to use the documented constructor syntax when the type being constructed has the same name as a property on the queried type. See fiddle. For example - .Where("it.DateTime > DateTime(2022, 1, 1, 0, 0, 0)")

This worked in versions at or prior to 1.0.22. It was broken in 1.0.23, presumably by #357. It continues to be broken in 1.2.24.

2. Exception

  Message: 
System.Linq.Dynamic.Core.Exceptions.ParseException : No applicable method 'DateTime' exists in type 'Foo'

  Stack Trace: 
ExpressionParser.ParseMemberAccess(Type type, Expression expression)
ExpressionParser.ParseIdentifier()
ExpressionParser.ParsePrimaryStart()
ExpressionParser.ParsePrimary()
ExpressionParser.ParseUnary()
ExpressionParser.ParseMultiplicative()
ExpressionParser.ParseAdditive()
ExpressionParser.ParseShiftOperator()
ExpressionParser.ParseComparisonOperator()
ExpressionParser.ParseLogicalAndOrOperator()
<20 more frames...>
ExpressionParser.ParseConditionalOperator()
ExpressionParser.Parse(Type resultType, Boolean createParameterCtor)
DynamicExpressionParser.ParseLambda(Type delegateType, ParsingConfig parsingConfig, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values)
DynamicExpressionParser.ParseLambda(ParsingConfig parsingConfig, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values)
DynamicExpressionParser.ParseLambda(ParsingConfig parsingConfig, Boolean createParameterCtor, Type itType, Type resultType, String expression, Object[] values)
DynamicQueryableExtensions.Where(IQueryable source, ParsingConfig config, String predicate, Object[] args)
DynamicQueryableExtensions.Where[TSource](IQueryable`1 source, ParsingConfig config, String predicate, Object[] args)
DynamicQueryableExtensions.Where[TSource](IQueryable`1 source, String predicate, Object[] args)

3. Fiddle or Project

https://dotnetfiddle.net/6j1G9U

4. Any further technical details

@StefH
Copy link
Collaborator

StefH commented Jan 13, 2023

Just a quick remark:

Did you try escaping the property DateTime like:

Where("@datetime

@ascott18
Copy link
Contributor Author

The exception is being throw about the constructor invocation DateTime(2022, 1, 1, 0, 0, 0), not the property access it.DateTime.

@StefH
Copy link
Collaborator

StefH commented Feb 4, 2023

@ascott18
The only way to solve this is to introduce a new config setting, which will have value false = old behavior. And set this to true when you want the new behavior (priority property over the type)

#664

A new NuGet version will be released in some time.

@StefH StefH closed this as completed Feb 4, 2023
@StefH StefH self-assigned this Feb 5, 2023
@StefH StefH added the feature label Feb 5, 2023
@StefH
Copy link
Collaborator

StefH commented Feb 14, 2023

@ascott18
This new config setting causes some backward compatibility issues some some users, so I'll probably need to change the default behavior back to version 1.2.24

So when a new version is released, 1.3.x, you 'll need to use the config setting correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants