Skip to content

ILC and ILLink don't respect TrimmerSingleWarn in some cases #94799

Closed

Description

@eerhardt

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

  1. ghost added
    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners
    on Nov 15, 2023
  2. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Nov 15, 2023
  3. added and removed
    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners
    on Nov 15, 2023
  4. eerhardt commented on Nov 15, 2023

    @eerhardt
    MemberAuthor
  5. MichalStrehovsky commented on Nov 15, 2023

    @MichalStrehovsky
    Member

    Is this from dotnet/linker#2087? That one was intentional. Do the original reasons not apply here?

  6. eerhardt commented on Nov 16, 2023

    @eerhardt
    MemberAuthor

    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.

  7. ghost removed
    untriagedNew issue has not been triaged by the area owner
    on Nov 16, 2023
  8. locked and limited conversation to collaborators on Dec 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions