New build-time warnings are introduced when upgrading from Injectio 5.2.2 to 6.0 in projects enabling AOT compilation or trimming.
Steps to reproduce
> dotnet --version
10.0.203
> dotnet new console
Replace the generated repro.csproj with:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<PublishAot>true</PublishAot>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Injectio" Version="5.2.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.7" />
</ItemGroup>
</Project>
And Program.cs with:
using Injectio.Attributes;
interface IRepro {}
[RegisterSingleton]
sealed class Repro : IRepro;
static class Program
{
static void Main() {}
}
Run dotnet build and note that no build-time warnings are emitted with Injectio 5.2.2.
Update Injectio to v6.0.0:
- <PackageReference Include="Injectio" Version="5.2.2" PrivateAssets="all" />
+ <PackageReference Include="Injectio" Version="6.0.0" PrivateAssets="all" />
Run dotnet build again to see build warnings newly introduced:
~/dev/repro/obj/Debug/net10.0/Injectio.Generators/Injectio.Generators.ServiceRegistrationGenerator/Injectio.Extensions.g.cs(158,32): warning IL2091: 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in 'Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider, params Object[])'. The generic parameter 'TDecorator' of 'Injectio.Extensions.DecorationExtensions.Decorate<TService, TDecorator>(IServiceCollection)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
~/dev/repro/obj/Debug/net10.0/Injectio.Generators/Injectio.Generators.ServiceRegistrationGenerator/Injectio.Extensions.g.cs(281,37): warning IL2091: 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in 'Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider, params Object[])'. The generic parameter 'TDecorator' of 'Injectio.Extensions.DecorationExtensions.DecorateKeyed<TService, TDecorator>(IServiceCollection, Object)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
~/dev/repro/obj/Debug/net10.0/Injectio.Generators/Injectio.Generators.ServiceRegistrationGenerator/Injectio.Extensions.g.cs(127,67): warning IL2072: 'instanceType' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider, Type, params Object[])'. The return value of method 'Microsoft.Extensions.DependencyInjection.ServiceDescriptor.ServiceType.get' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
~/dev/repro/obj/Debug/net10.0/Injectio.Generators/Injectio.Generators.ServiceRegistrationGenerator/Injectio.Extensions.g.cs(248,79): warning IL2072: 'instanceType' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider, Type, params Object[])'. The return value of method 'Microsoft.Extensions.DependencyInjection.ServiceDescriptor.ServiceType.get' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
~/dev/repro/obj/Debug/net10.0/Injectio.Generators/Injectio.Generators.ServiceRegistrationGenerator/Injectio.Extensions.g.cs(350,43): warning IL2055: Call to 'System.Type.MakeGenericType(params Type[])' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic type.
~/dev/repro/obj/Debug/net10.0/Injectio.Generators/Injectio.Generators.ServiceRegistrationGenerator/Injectio.Extensions.g.cs(350,43): warning IL3050: Using member 'System.Type.MakeGenericType(params Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime.
~/dev/repro/obj/Debug/net10.0/Injectio.Generators/Injectio.Generators.ServiceRegistrationGenerator/Injectio.Extensions.g.cs(370,49): warning IL2067: 'instanceType' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider, Type, params Object[])'. The parameter 'openDecoratorType' of method 'Injectio.Extensions.DecorationExtensions.DecorateOpenGeneric(IServiceCollection, Type, Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
~/dev/repro/obj/Debug/net10.0/Injectio.Generators/Injectio.Generators.ServiceRegistrationGenerator/Injectio.Extensions.g.cs(382,51): warning IL2067: 'instanceType' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider, Type, params Object[])'. The parameter 'openDecoratorType' of method 'Injectio.Extensions.DecorationExtensions.DecorateOpenGeneric(IServiceCollection, Type, Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
~/dev/repro/obj/Debug/net10.0/Injectio.Generators/Injectio.Generators.ServiceRegistrationGenerator/Injectio.Extensions.g.cs(395,153): warning IL2072: 'instanceType' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider, Type, params Object[])'. The return value of method 'Microsoft.Extensions.DependencyInjection.ServiceDescriptor.ServiceType.get' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
~/dev/repro/obj/Debug/net10.0/Injectio.Generators/Injectio.Generators.ServiceRegistrationGenerator/Injectio.Extensions.g.cs(395,45): warning IL2067: 'instanceType' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider, Type, params Object[])'. The parameter 'openDecoratorType' of method 'Injectio.Extensions.DecorationExtensions.DecorateOpenGeneric(IServiceCollection, Type, Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
~/dev/repro/obj/Debug/net10.0/Injectio.Generators/Injectio.Generators.ServiceRegistrationGenerator/Injectio.Extensions.g.cs(409,40): warning IL2067: 'instanceType' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider, Type, params Object[])'. The parameter 'openDecoratorType' of method 'Injectio.Extensions.DecorationExtensions.DecorateOpenGeneric(IServiceCollection, Type, Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
~/dev/repro/obj/Debug/net10.0/Injectio.Generators/Injectio.Generators.ServiceRegistrationGenerator/Injectio.Extensions.g.cs(420,40): warning IL2067: 'instanceType' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider, Type, params Object[])'. The parameter 'openDecoratorType' of method 'Injectio.Extensions.DecorationExtensions.DecorateOpenGeneric(IServiceCollection, Type, Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
~/dev/repro/obj/Debug/net10.0/Injectio.Generators/Injectio.Generators.ServiceRegistrationGenerator/Injectio.Extensions.g.cs(431,144): warning IL2072: 'instanceType' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider, Type, params Object[])'. The return value of method 'Microsoft.Extensions.DependencyInjection.ServiceDescriptor.ServiceType.get' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
~/dev/repro/obj/Debug/net10.0/Injectio.Generators/Injectio.Generators.ServiceRegistrationGenerator/Injectio.Extensions.g.cs(431,36): warning IL2067: 'instanceType' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider, Type, params Object[])'. The parameter 'openDecoratorType' of method 'Injectio.Extensions.DecorationExtensions.DecorateOpenGeneric(IServiceCollection, Type, Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
While Injectio makes no statement about AOT or trimming compatibility that I could find, some of these warnings seem avoidable by annotating the new decorator extensions with matching DynamicallyAccessedMembers attributes.
New build-time warnings are introduced when upgrading from Injectio 5.2.2 to 6.0 in projects enabling AOT compilation or trimming.
Steps to reproduce
Replace the generated
repro.csprojwith:And
Program.cswith:Run
dotnet buildand note that no build-time warnings are emitted with Injectio 5.2.2.Update Injectio to v6.0.0:
Run
dotnet buildagain to see build warnings newly introduced:While Injectio makes no statement about AOT or trimming compatibility that I could find, some of these warnings seem avoidable by annotating the new decorator extensions with matching
DynamicallyAccessedMembersattributes.