ParseException when using dotnet trimmer with TrimMode=full
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.
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.
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 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?