dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.37k stars 4.75k forks source link

Extra ILC warnings when PublishAOT=true on property with UnconditionalSuppressMessage #81129

Closed eerhardt closed 1 year ago

eerhardt commented 1 year ago

Summary

I'm getting an unexpected ILC warning when publishing an app that uses DependencyInjection.

ILC : AOT analysis warning IL3050: Microsoft.Extensions.DependencyInjection.ServiceLookup.IEnumerableCallSite.ServiceType.get: Using member 'System.Type.MakeGenericType(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime. [C:\DotNetTest\Net8Api\Net8Api.csproj]

However, this property has a suppression on it, so the warning shouldn't be emitted.

https://github.com/dotnet/runtime/blob/ae70a1c51a334a5e13fa22d500f8a8390052eef5/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/IEnumerableCallSite.cs#L24-L27

Repro Steps

dotnet publish the following app

(Note: in order to use the pre-release DependencyInjection package, you need a nuget.config for .NET 8 feed. Follow the instructions in https://github.com/dotnet/installer#installers-and-binaries)

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <PublishAot>true</PublishAot>
    <TrimmerSingleWarn>false</TrimmerSingleWarn>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0-alpha.1.23074.2" />
  </ItemGroup>
</Project>
using Microsoft.Extensions.DependencyInjection;

var c = new ServiceCollection();
c.BuildServiceProvider();

Console.WriteLine("done");

Expected results

There should be no warnings.

Actual results

I get the warning as above.

ghost commented 1 year ago

Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection See info in area-owners.md if you want to be subscribed.

Issue Details
### Summary I'm getting an unexpected ILC warning when publishing an app that uses DependencyInjection. ``` ILC : AOT analysis warning IL3050: Microsoft.Extensions.DependencyInjection.ServiceLookup.IEnumerableCallSite.ServiceType.get: Using member 'System.Type.MakeGenericType(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime. [C:\DotNetTest\Net8Api\Net8Api.csproj] ``` However, this property has a suppression on it, so the warning shouldn't be emitted. https://github.com/dotnet/runtime/blob/ae70a1c51a334a5e13fa22d500f8a8390052eef5/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/IEnumerableCallSite.cs#L24-L27 ### Repro Steps `dotnet publish` the following app (**Note**: in order to use the pre-release DependencyInjection package, you need a nuget.config for .NET 8 feed. Follow the instructions in https://github.com/dotnet/installer#installers-and-binaries) ```xml Exe net8.0 enable enable true false ``` ```C# using Microsoft.Extensions.DependencyInjection; var c = new ServiceCollection(); c.BuildServiceProvider(); Console.WriteLine("done"); ``` ### Expected results There should be no warnings. ### Actual results I get the warning as above.
Author: eerhardt
Assignees: -
Labels: `area-Extensions-DependencyInjection`
Milestone: -
MichalStrehovsky commented 1 year ago

You can probably work around by putting the suppression on the getter. We likely don't look at the associated property.

Cc @dotnet/ilc-contrib

eerhardt commented 1 year ago

We likely don't look at the associated property.

Note that the property below the one getting the warning is annotated the same way, and we aren't getting a warning for it. https://github.com/dotnet/runtime/blob/ae70a1c51a334a5e13fa22d500f8a8390052eef5/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/IEnumerableCallSite.cs#L29-L32

vitek-karas commented 1 year ago

This is the next bug I'm going to look at (hopefully today)... just please bear with me a little :wink: