Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
eerhardt opened this issue Nov 15, 2023 · 4 comments
Closed

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

eerhardt opened this issue Nov 15, 2023 · 4 comments

Comments

@eerhardt
Copy link
Member

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

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 15, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Nov 15, 2023
@eerhardt eerhardt added area-NativeAOT-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Nov 15, 2023
@ghost
Copy link

ghost commented Nov 15, 2023

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

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

Author: eerhardt
Assignees: -
Labels:

untriaged, area-NativeAOT-coreclr

Milestone: -

@eerhardt
Copy link
Member Author

cc @vitek-karas @sbomer

@MichalStrehovsky
Copy link
Member

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

@eerhardt
Copy link
Member Author

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.

@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Nov 16, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants