Repository navigation
ILC and ILLink don't respect TrimmerSingleWarn in some cases #94799
Copy link
Copy link
Closed
Labels
Description
Description
There are a class of trimming warnings that still get emitted as IL2026 from assemblies being referenced instead of the IL2104 that is supposed to be emitted when the warning comes from a referenced assembly.
Reproduction Steps
dotnet publish the following app
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.0.0" />
<PackageReference Include="Polly.Core" Version="8.2.0" />
</ItemGroup>
</Project>(Note the same behavior occurs with <PublishTrimmed>true</PublishTrimmed> instead of PublishAot.)
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services
.AddHttpClient<WeatherClient>()
.AddStandardResilienceHandler();
public class WeatherClient() { }Expected behavior
Since the referenced library Microsoft.Extensions.Http.Resilience has trimming warnings the only warning that should be emitted is a IL2104. This is the normal behavior when a referenced library has warnings.
Actual behavior
3 individual warnings are emitted instead:
ILC : Trim analysis warning IL2026: __OptionValidationStaticInstances.<Validators_g>F8B1F3D42962A35D8FF1B1489612AEF6C36F3713335EFF79DB68A25973333C495____Attributes..cctor(): Using member
'System.ComponentModel.DataAnnotations.RangeAttribute.RangeAttribute(Type,String,String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application c
ode. Generic TypeConverters may require the generic types to be annotated. For example, NullableConverter requires the underlying type to be DynamicallyAccessedMembers All. [C:\Users\eerh
ardt\source\repos\ConsoleApp103\ConsoleApp103\ConsoleApp103.csproj]
ILC : Trim analysis warning IL2026: __OptionValidationStaticInstances.<Validators_g>F8B1F3D42962A35D8FF1B1489612AEF6C36F3713335EFF79DB68A25973333C495____Attributes..cctor(): Using member
'System.ComponentModel.DataAnnotations.RangeAttribute.RangeAttribute(Type,String,String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application c
ode. Generic TypeConverters may require the generic types to be annotated. For example, NullableConverter requires the underlying type to be DynamicallyAccessedMembers All. [C:\Users\eerh
ardt\source\repos\ConsoleApp103\ConsoleApp103\ConsoleApp103.csproj]
ILC : Trim analysis warning IL2026: __OptionValidationStaticInstances.<Validators_g>F8B1F3D42962A35D8FF1B1489612AEF6C36F3713335EFF79DB68A25973333C495____Attributes..cctor(): Using member
'System.ComponentModel.DataAnnotations.RangeAttribute.RangeAttribute(Type,String,String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application c
ode. Generic TypeConverters may require the generic types to be annotated. For example, NullableConverter requires the underlying type to be DynamicallyAccessedMembers All. [C:\Users\eerh
ardt\source\repos\ConsoleApp103\ConsoleApp103\ConsoleApp103.csproj]
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
Activity
eerhardt commentedon Nov 15, 2023
cc @vitek-karas @sbomer
MichalStrehovsky commentedon Nov 15, 2023
Is this from dotnet/linker#2087? That one was intentional. Do the original reasons not apply here?
eerhardt commentedon Nov 16, 2023
Ah, good call. This is something I forgot about, and it wasn't obvious to me that the reason these warnings weren't being single-warned was because the library had IsTrimmable on it.
The good thing is that these warnings will be fixed by #94798, so they won't be seen soon.