SpyNet
SpyNet

Reputation: 679

How to use root descriptors trimming option in .NET?

I have a WinUI3/WinAppSDK app built with .NET 9. I want to enable Native AOT and Trimming for it but i get a few warnings for one NuGet package I use, DataGrid.

I have these in my CSProj file. Full version and the source code available here

<PublishTrimmed>true</PublishTrimmed>
<TrimMode>partial</TrimMode>
<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
<TrimmerSingleWarn>false</TrimmerSingleWarn>
<ItemGroup>
    <TrimmerRootDescriptor Include="MyRoots.xml" />
</ItemGroup>

And I defined assembly names in that XML file such as this

<linker>
  <assembly fullname="CommunityToolkit.WinUI.UI.Controls.DataGrid" preserve="all" />
</linker>

But it's not rooting the assemblies so that they won't be trimmed. I used the syntax defined here. I've tried many combinations but none of them seem to work. What am I doing wrong here? How are we supposed to use root descriptors?


Here are some of the warnings

1>/_/CommunityToolkit.WinUI.UI.Controls.DataGrid/Utilities/TypeHelper.cs(37): Trim analysis error IL2070: CommunityToolkit.WinUI.Utilities.TypeHelper.FindGenericType(Type,Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'System.Reflection.TypeInfo.ImplementedInterfaces.get'. The parameter 'type' of method 'CommunityToolkit.WinUI.Utilities.TypeHelper.FindGenericType(Type,Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
1>/_/CommunityToolkit.WinUI.UI.Controls.DataGrid/Utilities/TypeHelper.cs(268): Trim analysis error IL2070: CommunityToolkit.WinUI.Utilities.TypeHelper.GetPropertyOrIndexer(Type,String,Object[]&): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String)'. The parameter 'type' of method 'CommunityToolkit.WinUI.Utilities.TypeHelper.GetPropertyOrIndexer(Type,String,Object[]&)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
1>/_/CommunityToolkit.WinUI.UI.Controls.DataGrid/Utilities/TypeHelper.cs(278): Trim analysis error IL2070: CommunityToolkit.WinUI.Utilities.TypeHelper.GetPropertyOrIndexer(Type,String,Object[]&): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.PublicFields', 'DynamicallyAccessedMemberTypes.PublicNestedTypes', 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.PublicEvents' in call to 'System.Type.GetDefaultMembers()'. The parameter 'type' of method 'CommunityToolkit.WinUI.Utilities.TypeHelper.GetPropertyOrIndexer(Type,String,Object[]&)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
1>/_/CommunityToolkit.WinUI.UI.Controls.DataGrid/Utilities/TypeHelper.cs(378): Trim analysis error IL2075: CommunityToolkit.WinUI.Utilities.TypeHelper.SetNestedPropertyValue(Object&,Object,String): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String)'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
1>/_/CommunityToolkit.WinUI.UI.Controls.DataGrid/Utilities/TypeHelper.cs(389): Trim analysis error IL2075: CommunityToolkit.WinUI.Utilities.TypeHelper.SetNestedPropertyValue(Object&,Object,String): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String)'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
1>/_/CommunityToolkit.WinUI.UI.Controls.DataGrid/DataGrid/DataGrid.cs(8960): Trim analysis error IL2026: CommunityToolkit.WinUI.UI.Controls.DataGrid.ValidateEditingRow(Boolean,Boolean): Using member 'System.ComponentModel.DataAnnotations.ValidationContext.ValidationContext(Object,IServiceProvider,IDictionary`2<Object,Object>)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The Type of instance cannot be statically discovered and the Type's properties can be trimmed.
1>/_/CommunityToolkit.WinUI.UI.Controls.DataGrid/DataGrid/DataGrid.cs(8961): Trim analysis error IL2026: CommunityToolkit.WinUI.UI.Controls.DataGrid.ValidateEditingRow(Boolean,Boolean): Using member 'System.ComponentModel.DataAnnotations.Validator.TryValidateObject(Object,ValidationContext,ICollection`1<ValidationResult>,Boolean)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The Type of instance cannot be statically discovered and the Type's properties can be trimmed.
1>/_/CommunityToolkit.WinUI.UI.Controls.DataGrid/DataGrid/DataGridComboBoxColumn.cs(617): Trim analysis error IL2075: CommunityToolkit.WinUI.UI.Controls.DataGridComboBoxColumn.GetDisplayValue(Object): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String)'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
1>/_/CommunityToolkit.WinUI.UI.Controls.DataGrid/DataGrid/DataGridComboBoxColumn.cs(665): Trim analysis error IL2075: CommunityToolkit.WinUI.UI.Controls.DataGridComboBoxColumn.EnsureDisplayMemberPathExists(): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperties()'. The return value of method 'CommunityToolkit.WinUI.UI.Utilities.Extensions.GetItemType(IEnumerable)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
1>/_/CommunityToolkit.WinUI.UI.Controls.DataGrid/DataGrid/DataGridComboBoxColumn.cs(678): Trim analysis error IL2075: CommunityToolkit.WinUI.UI.Controls.DataGridComboBoxColumn.EnsureItemsSourceBinding(): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperties()'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
1>/_/CommunityToolkit.WinUI.UI.Controls.DataGrid/obj/Release/net5.0-windows10.0.18362.0/XamlTypeInfo.g.cs(2289): Trim analysis error IL2059: CommunityToolkit.WinUI.UI.Controls.CommunityToolkit_WinUI_UI_Controls_DataGrid_XamlTypeInfo.XamlUserType.RunInitializer(): Unrecognized value passed to the parameter 'type' of method 'System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(RuntimeTypeHandle)'. It's not possible to guarantee the availability of the target static constructor.
1>/_/CommunityToolkit.WinUI.UI.Controls.DataGrid/DataGrid/DataGridDataConnection.cs(1023): Trim analysis error IL2075: CommunityToolkit.WinUI.UI.Controls.DataGridInternals.DataGridDataConnection.UpdateDataProperties(): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperties(BindingFlags)'. The return value of method 'CommunityToolkit.WinUI.UI.Controls.DataGridInternals.DataGridDataConnection.DataType.get' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
1>/_/CommunityToolkit.WinUI.UI.Controls.DataGrid/CollectionViews/CollectionView.cs(890): Trim analysis error IL2075: CommunityToolkit.WinUI.UI.Data.Utilities.CollectionView.GetItemType(Boolean): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'System.Type.GetInterfaces()'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
1>/_/CommunityToolkit.WinUI.UI.Controls.DataGrid/Utilities/ValidationUtil.cs(225): Trim analysis error IL2075: CommunityToolkit.WinUI.UI.Data.Utilities.ValidationUtil.GetDependencyProperties(FrameworkElement,Boolean): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields' in call to 'System.Type.GetFields(BindingFlags)'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
1>/_/CommunityToolkit.WinUI.UI.Controls.DataGrid/DataGrid/DataGridComboBoxColumn.cs(276): Trim analysis error IL2075: CommunityToolkit.WinUI.UI.Controls.DataGridComboBoxColumn.<>c__DisplayClass41_0.<GenerateEditingElement>b__0(Object,SelectionChangedEventArgs): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String)'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.

Upvotes: 0

Views: 127

Answers (0)

Related Questions