runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Extra ILC warnings when PublishAOT=true on method already marked RequiresUnreferencedCode

Open eerhardt opened this issue 3 years ago • 0 comments

Description

When Publishing AOT, I'm seeing extra warnings being emitted that clutter the warnings and confuse developers.

From what I can tell, the warnings are coming from:

https://github.com/dotnet/runtime/blob/2f3fcca06499725469b6ae021be960e08d808c75/src/libraries/Microsoft.Extensions.Logging.Configuration/src/LoggerProviderConfigurationExtensions.cs#L25-L29

ServiceDescriptor.Singleton has a [DAM] attribute for the constructor of the 2nd generic arg:

https://github.com/dotnet/runtime/blob/2f3fcca06499725469b6ae021be960e08d808c75/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ServiceDescriptor.cs#L302

and LoggerProviderConfigureOptions has RDC and RUC on its ctor:

https://github.com/dotnet/runtime/blob/2f3fcca06499725469b6ae021be960e08d808c75/src/libraries/Microsoft.Extensions.Logging.Configuration/src/LoggerProviderConfigureOptions.cs#L14-L16

However, these warnings shouldn't be emitted because RegisterProviderOptions has RDC and RUC attributes. So I should only be getting the warnings from my call to RegisterProviderOptions.

cc @MichalStrehovsky @vitek-karas

Reproduction Steps

Using 7.0-rc1, dotnet publish -c Release -r win-x64 the following app:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <PublishAOT>true</PublishAOT>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0-rc.1.22426.10" />
  </ItemGroup>
</Project>
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Configuration;
using Microsoft.Extensions.Logging.Console;

LoggerProviderOptions.RegisterProviderOptions<ConsoleLoggerOptions, ConsoleLoggerProvider>(new ServiceCollection());

Expected behavior

I should only get warnings for my program's call to RegisterProviderOptions.

Actual behavior

Along with the expected warnings from my code, I'm getting these extra warnings in the publish output:

ILC : Trim analysis warning IL2026: Microsoft.Extensions.DependencyInjection.ServiceDescriptor.Singleton<IConfigureOptions`1<ConsoleLoggerOptions>,LoggerProviderConfigureOptions`2<ConsoleLoggerOptions,ConsoleLoggerProvider>>(): Using member 'Microsoft.Extensions.Logging.Configuration.LoggerProviderConfigureOptions`2<ConsoleLoggerOptions,ConsoleLoggerProvider>.LoggerProviderConfigureOptions`2<ConsoleLoggerOptions,ConsoleLoggerProvider>(ILoggerProviderConfiguration`1<ConsoleLoggerProvider>)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. TOptions's dependent types may have their members trimmed. Ensure all required members are preserved. [C:\Users\eerhardt\source\repos\WorkerService12\WorkerService12\WorkerService12.csproj]
ILC : Trim analysis warning IL2026: Microsoft.Extensions.DependencyInjection.ServiceDescriptor.Describe<IConfigureOptions`1<ConsoleLoggerOptions>,LoggerProviderConfigureOptions`2<ConsoleLoggerOptions,ConsoleLoggerProvider>>(ServiceLifetime): Using member 'Microsoft.Extensions.Logging.Configuration.LoggerProviderConfigureOptions`2<ConsoleLoggerOptions,ConsoleLoggerProvider>.LoggerProviderConfigureOptions`2<ConsoleLoggerOptions,ConsoleLoggerProvider>(ILoggerProviderConfiguration`1<ConsoleLoggerProvider>)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. TOptions's dependent types may have their members trimmed. Ensure all required members are preserved. [C:\Users\eerhardt\source\repos\WorkerService12\WorkerService12\WorkerService12.csproj]

Regression?

I'm not sure. Probably not.

Known Workarounds

No response

Configuration

No response

Other information

No response

eerhardt avatar Sep 20 '22 15:09 eerhardt