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

Doc: Method call in custom type raises "No applicable method '' exists in type ''" ParseException #721

Open
jhpetersen opened this issue Jul 7, 2023 · 2 comments
Assignees

Comments

@jhpetersen
Copy link

1. Description

I am trying to upgrade from Linq.Dynamic.Core 1.2.25 to 1.3.3 and facing runtime ParserExcpetions on DynamicExpressionParser.ParseLambda call No applicable method 'SomeMethod' exists in type 'MyCustomType'.

I've read the note on breaking change from 1.3.0 about having to register any classes from which a method should be callable (tested both ways with an attribute and a custom type provider), but that is not the problem (otherwise a Methods on type 'MyCustomType' are not accessible would have been thrown).

2. Exception

Exception from the first fiddle:

No applicable method 'GetSomeValue' exists in type 'MyCustomClass' (at index 14)
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseMemberAccess(Type type, Expression expression) in C:\Dev\GitHub\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\Parser\ExpressionParser.cs:line 1753
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseTypeAccess(Type type, Boolean getNext) in C:\Dev\GitHub\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\Parser\ExpressionParser.cs:line 1661
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIdentifier() in C:\Dev\GitHub\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\Parser\ExpressionParser.cs:line 941
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParsePrimaryStart() in C:\Dev\GitHub\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\Parser\ExpressionParser.cs:line 817
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParsePrimary() in C:\Dev\GitHub\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\Parser\ExpressionParser.cs:line 785
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseUnary() in C:\Dev\GitHub\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\Parser\ExpressionParser.cs:line 780
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseMultiplicative() in C:\Dev\GitHub\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\Parser\ExpressionParser.cs:line 725
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAdditive() in C:\Dev\GitHub\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\Parser\ExpressionParser.cs:line 692
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseShiftOperator() in C:\Dev\GitHub\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\Parser\ExpressionParser.cs:line 668
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseComparisonOperator() in C:\Dev\GitHub\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\Parser\ExpressionParser.cs:line 456
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLogicalAndOrOperator() in C:\Dev\GitHub\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\Parser\ExpressionParser.cs:line 388
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIn() in C:\Dev\GitHub\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\Parser\ExpressionParser.cs:line 299
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAndOperator() in C:\Dev\GitHub\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\Parser\ExpressionParser.cs:line 282
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseOrOperator() in C:\Dev\GitHub\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\Parser\ExpressionParser.cs:line 264
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLambdaOperator() in C:\Dev\GitHub\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\Parser\ExpressionParser.cs:line 244
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseNullCoalescingOperator() in C:\Dev\GitHub\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\Parser\ExpressionParser.cs:line 231
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseConditionalOperator() in C:\Dev\GitHub\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\Parser\ExpressionParser.cs:line 215
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.Parse(Type resultType, Boolean createParameterCtor) in C:\Dev\GitHub\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\Parser\ExpressionParser.cs:line 153
   at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(Type delegateType, ParsingConfig parsingConfig, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values) in C:\Dev\GitHub\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\DynamicExpressionParser.cs:line 121
   at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(ParsingConfig parsingConfig, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values) in C:\Dev\GitHub\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\DynamicExpressionParser.cs:line 98
   at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(ParameterExpression[] parameters, Type resultType, String expression, Object[] values) in C:\Dev\GitHub\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\DynamicExpressionParser.cs:line 392

3. Fiddle or Project

I created two test fiddles:
one demonstrating the issue with 1.3.3 and a second working with 1.2.25

4. Any further technical details

If one adds the DynamicLinqType() Attribute on MyCustomClass in the second fiddle, a similar exception is thrown, so this probably has something to do with handling member access in custom types in general.

(i would have digged deeper to find the root cause, but could not download symbol files from nuget server, so debugging inside DynamicLinq.Core was not possible)

Thanks for any help on this

@jhpetersen jhpetersen changed the title params array in custom type method raises "No applicable method '' exists in type ''" ParseException method call in custom type method raises "No applicable method '' exists in type ''" ParseException Jul 7, 2023
@jhpetersen jhpetersen changed the title method call in custom type method raises "No applicable method '' exists in type ''" ParseException method call in custom type raises "No applicable method '' exists in type ''" ParseException Jul 7, 2023
@abbasc52
Copy link
Contributor

abbasc52 commented Aug 14, 2023

@jhpetersen this issue is related to #727
If Type name is the same as the input parameter name, it gives Type precedence.

Workaround is using different name for input from type

@jhpetersen
Copy link
Author

Wow, thanks, i would never have suspected that to be the cause 😮 👍
I modified the parameter name as a trial and it worked:

var multipleParamsExpression = $"FooBar.{nameof(MyCustomClass.GetSomeValue)}(input)";
var multipleParamsExpressionParams = new ParameterExpression[] {
   Expression.Parameter(typeof(MyCustomClass), "FooBar"),
   Expression.Parameter(typeof(int), "input")
};

(Nevertheless should be fixed or well documented..)

@StefH StefH self-assigned this Sep 10, 2023
@StefH StefH changed the title method call in custom type raises "No applicable method '' exists in type ''" ParseException Doc: Method call in custom type raises "No applicable method '' exists in type ''" ParseException Sep 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants