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

Using Trim() on string field throws ParseException: 'No applicable method 'Trim' exists in type 'String'' #492

Closed
vologar opened this issue Mar 24, 2021 · 3 comments
Assignees
Labels

Comments

@vologar
Copy link

vologar commented Mar 24, 2021

Using the latest nuget package 1.2.8 of System.Linq.Dynamic.Core.

Exception is thrown when using Trim() on a string field.

Exception

System.Linq.Dynamic.Core.Exceptions.ParseException:
Exception message:
'No applicable method 'Trim' exists in type 'String''
Stack trace:
System.Linq.Dynamic.Core.Exceptions.ParseException
  HResult=0x80131500
  Message=No applicable method 'Trim' exists in type 'String'
  Source=System.Linq.Dynamic.Core
  StackTrace:
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseMemberAccess(Type type, Expression expression)
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParsePrimary()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseUnary()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseMultiplicative()
   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[T,TResult](ParsingConfig parsingConfig, Boolean createParameterCtor, String expression, Object[] values)
   at TestDynamicLinq.frmTest.btnTest_Click(Object sender, EventArgs e) in D:\Code\System.Linq.Dynamic.Core-master\System.Linq.Dynamic.Core-master\TestDynamicLinq\frmTest.cs:line 29
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at TestDynamicLinq.Program.Main() in D:\Code\System.Linq.Dynamic.Core-master\System.Linq.Dynamic.Core-master\TestDynamicLinq\Program.cs:line 19

3. Code to reproduce

public class Person
    {        public string Name { get; set; }           }

string query = "Name.Trim()=\"John\""; 
var exp = DynamicExpressionParser.ParseLambda<Person, bool>(null, false, query, null); // throws exception

4. Any further technical details

The code works with ToUpper() and ToLower() extensions methods.
e.g string query = "Name.ToUpper()="John""; // does not throw an exception

Trim() works when referencing the github solution directly. But throws the exception when using the latest nuget package. What am I missing? Is there a workaround for this?

@vologar
Copy link
Author

vologar commented Mar 24, 2021

Looks like the changes made to IsBetterThan(Expression[] args, MethodData first, MethodData second) in MethodFinder class to handle 0 args are not in the latest package yet.
The following works in the meantime : "Name.Trim(new char[] {' '})="John"" ; // use Trim with parameters because parametless version is not handled correctly for now.

@StefH StefH added the question label Mar 24, 2021
@StefH StefH self-assigned this Mar 24, 2021
@StefH
Copy link
Collaborator

StefH commented Mar 25, 2021

Hello @vologar, I'll try to release a new package this weekend.

@vologar
Copy link
Author

vologar commented Mar 26, 2021

Got the latest package. The issue is no longer there. The code is working with Trim(). Thank you.

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