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

Native AoT trim analysis warning : WithLinkGeneratorDecorator #1094

Open
1 task done
Jflaurendeau opened this issue Jun 9, 2024 · 0 comments
Open
1 task done

Native AoT trim analysis warning : WithLinkGeneratorDecorator #1094

Jflaurendeau opened this issue Jun 9, 2024 · 0 comments

Comments

@Jflaurendeau
Copy link

Jflaurendeau commented Jun 9, 2024

Is there an existing issue for this?

  • 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.

var decoratedType = descriptor switch
{
{ ImplementationType: var type } when type is not null => type,
{ ImplementationInstance: var instance } when instance is not null => instance.GetType(),
_ => throw new InvalidOperationException(),
};
services.Replace( Describe( decoratedType, decoratedType, lifetime ) );

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant