aspnet-api-versioning
aspnet-api-versioning copied to clipboard
Native AoT trim analysis warning : WithLinkGeneratorDecorator
Is there an existing issue for this?
- [x] I have searched the existing issues
Describe the bug
I was playing with native AoT and had a trim analysis warning IL2072.
ILC : Trim analysis warning IL2072: Microsoft.Extensions.DependencyInjection.IServiceCollectionExtensions.WithLinkGeneratorDecorator(IServiceCollection): 'implementationType' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'Microsoft.Extensions.DependencyInjection.ServiceDescriptor.Describe(Type,Type,ServiceLifetime)'. The return value of method 'System.Object.GetType()' 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.
Steps To Reproduce
Package:
<ItemGroup>
<PackageReference Include="Asp.Versioning.Http" Version="8.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
</ItemGroup>
Services used:
var builder = WebApplication.CreateSlimBuilder(args);
builder.Services.ConfigureHttpJsonOptions(options =>
{
options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
});
builder.Services.AddApiVersioning(options =>
{
options.DefaultApiVersion = new ApiVersion(1);
options.AssumeDefaultVersionWhenUnspecified = true;
options.ApiVersionReader = ApiVersionReader.Combine(
new UrlSegmentApiVersionReader(),
new HeaderApiVersionReader("Api-Version"),
new QueryStringApiVersionReader()); // default: ?api-version=X.Y
});
var app = builder.Build();
Exceptions (if any)
No response
.NET Version
8
Anything else?
I think this is related to the instance at line 177, used at line 181.
https://github.com/dotnet/aspnet-api-versioning/blob/3fc071913dcded23eeb5ebe55bca44f3828488bf/src/AspNetCore/WebApi/src/Asp.Versioning.Http/DependencyInjection/IServiceCollectionExtensions.cs#L174-L181
It is just a warning and based on my code path, the ImplementationInstance branch of the switch expression should not be hit.
This might not be an issue or you may already know a work around, but I did not find any comment on this warning, so I though I should share it.
First time writing an item on an OSS project. I read the code of conduct and etiquette, but feel free to share other unwritten rules if this post should be improved.