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

DelegatingOptionsFactoryServiceCollectionExtensions breaks native AoT compatibility #5518

Closed
martincostello opened this issue Apr 8, 2024 · 1 comment · Fixed by #5520
Closed
Labels
bug Something isn't working pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package
Milestone

Comments

@martincostello
Copy link
Contributor

martincostello commented Apr 8, 2024

Bug Report

List of all OpenTelemetry NuGet packages and version that you are using (e.g. OpenTelemetry 1.0.2):

  • OpenTelemetry 1.8.0
  • OpenTelemetry.Exporter.OpenTelemetryProtocol 1.8.0
  • OpenTelemetry.Extensions.Hosting 1.8.0
  • OpenTelemetry.Instrumentation.AWS 1.1.0-beta.3
  • OpenTelemetry.Instrumentation.AWSLambda 1.3.0-beta.1
  • OpenTelemetry.Instrumentation.Http 1.8.0

Runtime version: net9.0

Symptom

Compiling a native AoT application with .NET 9 preview 2 fails when OpenTelemetry 1.8.0 is used in the application.

What is the expected behavior?

The application successfully compiles.

What is the actual behavior?

The application fails to compile due to warnings associated with the DelegatingOptionsFactoryServiceCollectionExtensions type:

  LondonTravel.Skill failed with errors (45.7s) → artifacts\bin\LondonTravel.Skill\release\LondonTravel.Skill.dll
    ILC : Trim analysis error IL2091: Microsoft.Extensions.DependencyInjection.DelegatingOptionsFactoryServiceCollectionExtensions.RegisterOptionsFactory<T>(IServiceCollection,Func`2<IConfiguration,!!0>): 'TOptions' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in 'Microsoft.Extensions.Options.IOptionsFactory`1'. The generic parameter 'T' of 'Microsoft.Extensions.DependencyInjection.DelegatingOptionsFactoryServiceCollectionExtensions.RegisterOptionsFactory<T>(IServiceCollection,Func`2<IConfiguration,!!0>)' 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. [C:\Coding\martincostello\alexa-london-travel\src\LondonTravel.Skill\LondonTravel.Skill.csproj]
    ILC : Trim analysis error IL2091: Microsoft.Extensions.DependencyInjection.DelegatingOptionsFactoryServiceCollectionExtensions.RegisterOptionsFactory<T>(IServiceCollection,Func`2<IConfiguration,!!0>): 'TOptions' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in 'Microsoft.Extensions.Options.IOptionsFactory`1'. The generic parameter 'T' of 'Microsoft.Extensions.DependencyInjection.DelegatingOptionsFactoryServiceCollectionExtensions.RegisterOptionsFactory<T>(IServiceCollection,Func`2<IConfiguration,!!0>)' 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. [C:\Coding\martincostello\alexa-london-travel\src\LondonTravel.Skill\LondonTravel.Skill.csproj]
    ILC : Trim analysis error IL2091: Microsoft.Extensions.DependencyInjection.DelegatingOptionsFactoryServiceCollectionExtensions.<>c__DisplayClass0_0`1.<RegisterOptionsFactory>b__0(IServiceProvider): 'TOptions' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in 'Microsoft.Extensions.Options.IOptionsFactory`1'. The generic parameter 'T' of 'Microsoft.Extensions.DependencyInjection.DelegatingOptionsFactoryServiceCollectionExtensions.<>c__DisplayClass0_0`1' 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. [C:\Coding\martincostello\alexa-london-travel\src\LondonTravel.Skill\LondonTravel.Skill.csproj]
    ILC : Trim analysis error IL2091: Microsoft.Extensions.DependencyInjection.DelegatingOptionsFactoryServiceCollectionExtensions.RegisterOptionsFactory<T>(IServiceCollection,Func`4<IServiceProvider,IConfiguration,String,!!0>): 'TOptions' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in 'Microsoft.Extensions.Options.IOptionsFactory`1'. The generic parameter 'T' of 'Microsoft.Extensions.DependencyInjection.DelegatingOptionsFactoryServiceCollectionExtensions.RegisterOptionsFactory<T>(IServiceCollection,Func`4<IServiceProvider,IConfiguration,String,!!0>)' 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. [C:\Coding\martincostello\alexa-london-travel\src\LondonTravel.Skill\LondonTravel.Skill.csproj]
    ILC : Trim analysis error IL2091: Microsoft.Extensions.DependencyInjection.DelegatingOptionsFactoryServiceCollectionExtensions.RegisterOptionsFactory<T>(IServiceCollection,Func`4<IServiceProvider,IConfiguration,String,!!0>): 'TOptions' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in 'Microsoft.Extensions.Options.IOptionsFactory`1'. The generic parameter 'T' of 'Microsoft.Extensions.DependencyInjection.DelegatingOptionsFactoryServiceCollectionExtensions.RegisterOptionsFactory<T>(IServiceCollection,Func`4<IServiceProvider,IConfiguration,String,!!0>)' 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. [C:\Coding\martincostello\alexa-london-travel\src\LondonTravel.Skill\LondonTravel.Skill.csproj]
    ILC : Trim analysis error IL2091: Microsoft.Extensions.DependencyInjection.DelegatingOptionsFactoryServiceCollectionExtensions.<>c__DisplayClass1_0`1.<RegisterOptionsFactory>b__0(IServiceProvider): 'TOptions' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in 'Microsoft.Extensions.Options.IOptionsFactory`1'. The generic parameter 'T' of 'Microsoft.Extensions.DependencyInjection.DelegatingOptionsFactoryServiceCollectionExtensions.<>c__DisplayClass1_0`1' 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. [C:\Coding\martincostello\alexa-london-travel\src\LondonTravel.Skill\LondonTravel.Skill.csproj]
    ILC : Trim analysis error IL2091: Microsoft.Extensions.Options.DelegatingOptionsFactory`1: 'TOptions' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in 'Microsoft.Extensions.Options.IOptionsFactory`1'. The generic parameter 'TOptions' of 'Microsoft.Extensions.Options.DelegatingOptionsFactory`1' 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. [C:\Coding\martincostello\alexa-london-travel\src\LondonTravel.Skill\LondonTravel.Skill.csproj]

This doesn't occur with .NET 8 - unless there's a bug with the native AoT compiler, my assumption is that new annotations have been added to the runtime in .NET 9 which create new warnings/incompatibilities.

Reproduce

Originally found with martincostello/alexa-london-travel@3a0e406 with /p:TrimmerSingleWarn=false.

For a simpler repro see verify-aot-compat failures in #5519 (example).

Additional Context

None.

/cc @eerhardt

@martincostello
Copy link
Contributor Author

Looks like this isn't specific to .NET 9 after all - #5520 shows it fails against main and .NET 8.

@martincostello martincostello changed the title DelegatingOptionsFactoryServiceCollectionExtensions breaks native AoT compatibility with .NET 9 preview 2 DelegatingOptionsFactoryServiceCollectionExtensions breaks native AoT compatibility Apr 8, 2024
@CodeBlanch CodeBlanch added the pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package label Apr 10, 2024
@CodeBlanch CodeBlanch added this to the 1.8.1 milestone Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants