System.Linq.Dynamic.Core icon indicating copy to clipboard operation
System.Linq.Dynamic.Core copied to clipboard

ParseException when using dotnet trimmer with TrimMode=full

Open tranb3r opened this issue 2 years ago • 2 comments

1. Description

I'm using DynamicExpressionParser.ParseLambda in a dotnet console application. The expression I'm parsing is pretty simple, and it involves comparing an integer and a byte. It's working just as expected, unless I'm using the dotnet trimmer in full mode, in which case it's raising a ParseException. I've already tried to root assembly System.Linq.Dynamic.Core for the trimmer, but it doesn't fix the issue. Could you please help me find a solution?

2. Exception

System.Linq.Dynamic.Core.Exceptions.ParseException
Operator '==' incompatible with operand types 'Byte' and 'Int32'
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.CheckAndPromoteOperands(Type, TokenId, String, Expression&, Expression&, Int32)
   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 , Boolean )
   at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(Type, ParsingConfig, Boolean, ParameterExpression[] , Type, String , Object[] )
   at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(ParsingConfig , Boolean, ParameterExpression[], Type , String, Object[] )
   at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda[T,TResult](ParsingConfig, Boolean, String , Object[] )
   at SldcTrimmer.LambdaExtensions.ParseLambda[T1,T2](String) in D:\Dev\Zitch\Issues\SldcTrimmer\SldcTrimmer\LambdaExtensions.cs:line 10
   at SldcTrimmer.Program.Main(String[]) in D:\Dev\Zitch\Issues\SldcTrimmer\SldcTrimmer\Program.cs:line 14

3. Fiddle or Project

Here is a repro: https://github.com/tranb3r/Issues/tree/main/SldcTrimmer Try first launching the app from VS, in debug or release: no issue. Then, publish the app. It will run the trimmer. Then run the published SldcTrimmer.exe: it fails.

4. Any further technical details

Here is a warning that is shown when publishing the app. Assembly 'System.Linq.Dynamic.Core' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries. But I have no idea how I can get more information and investigate more.

tranb3r avatar Mar 02 '23 10:03 tranb3r

Hello @tranb3r, Thanks for the detailed description, I'll need some time to investigate. When I've a result or questions, I'll report back.

StefH avatar Mar 03 '23 18:03 StefH

Just for information, I can workaround this exception by adding to my app these attributes when calling SLDC:

[DynamicDependency(DynamicallyAccessedMemberTypes.All, "System.Linq.Dynamic.Core.Parser.SupportedOperands.IArithmeticSignatures", "System.Linq.Dynamic.Core")]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, "System.Linq.Dynamic.Core.Parser.SupportedOperands.ILogicalSignatures", "System.Linq.Dynamic.Core")]

tranb3r avatar Jan 24 '24 08:01 tranb3r

@tranb3r This specific error will be solved by https://github.com/zzzprojects/System.Linq.Dynamic.Core/pull/839, however I do not know if there are more issues.

Did you encounter any other problems while trimming?

StefH avatar Aug 21 '24 20:08 StefH