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

AoT: Microsoft.Extensions.DependencyInjection issue? #4445

Closed
CodeBlanch opened this issue Apr 26, 2023 · 0 comments
Closed

AoT: Microsoft.Extensions.DependencyInjection issue? #4445

CodeBlanch opened this issue Apr 26, 2023 · 0 comments
Assignees
Labels
Milestone

Comments

@CodeBlanch
Copy link
Member

Relates to #3429

On #4441 I added some code which calls...

Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider

...which generated a trim warning...

AOT analysis warning IL3050: OpenTelemetry.Logs.LoggerProviderServiceCollectionBuilder.Build(): Using member 'Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection,Boolean)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. Using Microsoft.Extensions.DependencyInjection requires generating code dynamically at runtime. For example, when using enumerable and generic ValueType services.

It looks like in .NET 7 RequiresDynamicCodeAttribute was added: dotnet/runtime#73829

And then it was removed in .NET 8: dotnet/runtime#79286

My take after reading the runtime issues is for Microsoft.Extensions.DependencyInjection...

  • <= .NET 6, no AoT warning. Probably safe. Only requires dynamic code for edge cases.
  • == .NET 7, AoT warning always.
  • >= .NET 8, no AoT warning unless dynamic code is actually used.

It seems like the best thing to do would be to upgrade to Microsoft.Extensions.DependencyInjection v8 when it is released but that is probably going to be problematic for auto-instrumentation and people wrapping OTel SDK into other libraries.

Opening this issue for tracking.

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

No branches or pull requests

4 participants