dotnet / linker

389 stars 126 forks source link

net6.0 apps have trimming warnings #2998

Closed sbomer closed 2 years ago

sbomer commented 2 years ago

Creating this as a tracking issue for the back-compat issue noticed by @vitek-karas.

Using a recent 7.0 SDK to trim a net6.0 app produces trimming warnings. Some are new warning codes we added, and some are due to changes in the analysis (for example, ref param warnings are surfaced with different warning codes).

Here is an example of the warnings, from a helloworld app:

ILLink : Trim analysis warning IL2070: System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1&, RuntimeModule, Int32, RuntimeType, Boolean, RuntimeType.ListBuilder<Object>): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String, Type, Type[])'. The parameter 'attributeType' of method 'System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken, MetadataImport&, RuntimeModule, MetadataToken, RuntimeType, Boolean, ListBuilder`1&, RuntimeType&, IRuntimeMethodInfo&, Boolean&)' 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.
ILLink : Trim analysis warning IL2070: System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1&, RuntimeModule, Int32, RuntimeType, Boolean, RuntimeType.ListBuilder<Object>): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String)'. The parameter 'attributeType' of method 'System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken, MetadataImport&, RuntimeModule, MetadataToken, RuntimeType, Boolean, ListBuilder`1&, RuntimeType&, IRuntimeMethodInfo&, Boolean&)' 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.
ILLink : Trim analysis warning IL2070: System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1&, RuntimeModule, Int32, RuntimeType, Boolean, RuntimeType.ListBuilder<Object>): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields' in call to 'System.Type.GetField(String)'. The parameter 'attributeType' of method 'System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken, MetadataImport&, RuntimeModule, MetadataToken, RuntimeType, Boolean, ListBuilder`1&, RuntimeType&, IRuntimeMethodInfo&, Boolean&)' 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.
ILLink : Trim analysis warning IL2119: System.Diagnostics.Tracing.EventSource.<WriteEventString>g__GetTrimSafeTraceLoggingEventTypes|76_0(): 'DynamicallyAccessedMemberAttribute' on 'System.Diagnostics.Tracing.EventSource' or one of its base types references compiler-generated member 'System.Diagnostics.Tracing.EventSource.<WriteEventString>g__GetTrimSafeTraceLoggingEventTypes|76_0()'.
ILLink : Trim analysis warning IL2067: System.RuntimeTypeHandle.CreateInstanceForAnotherGenericParameter(RuntimeType, RuntimeType): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.RuntimeTypeHandle.CreateInstanceForAnotherGenericParameter(RuntimeType, RuntimeType)'. The parameter 'type' of method 'System.Runtime.CompilerServices.QCallTypeHandle.QCallTypeHandle(RuntimeType&)' 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.

The plan is to ship a suppression XML that is used when targeting net6.0, as a short-term solution. We will need to discuss long-term approaches separately.