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

Unable to find my string extensions in static class with DynamicLinqType attribute #831

Closed
JvDriel opened this issue Jul 25, 2024 · 1 comment
Assignees
Labels

Comments

@JvDriel
Copy link

JvDriel commented Jul 25, 2024

1. Description

From version 1.3.10 to 1.3.12 extension methods on string stopped working

I get an exception:

System.Linq.Dynamic.Core.Exceptions.ParseException: No applicable method 'EmptyIfNull' exists in type 'String'

[TestMethod]
public void GetStringFunctionTest_()
{
    var sourceStringParameter = Expression.Parameter(typeof(string), "s");
    var parsingConfig = new ParsingConfig { SupportEnumerationsFromSystemNamespace = true };
    var expression = "s.EmptyIfNull()";
    DynamicExpressionParser.ParseLambda(parsingConfig, false, [sourceStringParameter], typeof(object), expression).Compile();
}
[DynamicLinqType]
public static class DynamicLinqTypeExtensions
{
    public static string EmptyIfNull(this string s)
    {
        return s ?? string.Empty;
    }
}

2. Exception

Stacktrace:

System.Linq.Dynamic.Core.Exceptions.ParseException: No applicable method 'EmptyIfNull' exists in type 'String'
    at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseMemberAccess(Type type, Expression expression, String id)
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParsePrimary()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseUnary()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseArithmetic()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAdditive()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseShiftOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseComparisonOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLogicalAndOrOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIn()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAndOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseOrOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLambdaOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseNullCoalescingOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseConditionalOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.Parse(Type resultType, Boolean createParameterCtor)
   at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(Type delegateType, ParsingConfig parsingConfig, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values)
   at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(ParsingConfig parsingConfig, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values)

3. Fiddle or Project

Not sure if that's possible in this case

4. Any further technical details

Running from testproject with net8.0

@StefH StefH self-assigned this Jul 29, 2024
@StefH StefH added the bug label Jul 29, 2024
@StefH
Copy link
Collaborator

StefH commented Jul 29, 2024

#832

@StefH StefH closed this as completed Jul 29, 2024
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