Elastic.Apm.Extensions.Hosting doesn't work with net48 if you already have a dependency on Microsoft.Extensions.DependencyInjection version 5.0

I've created a small Gist to illustrate it.

But, if you have a net48 app which already have dependencies to Microsoft.Extensions.DependencyInjection version 5.0 and you add Elastic.Apm.Extensions.Hosting you'll get the following exception:

System.MissingMethodException: Method not found: 'Microsoft.Extensions.Hosting.IHostingEnvironment Microsoft.Extensions.Hosting.HostBuilderContext.get_HostingEnvironment()'.
   at Elastic.Apm.Extensions.Hosting.HostBuilderExtensions.<>c__DisplayClass0_1.<UseElasticApm>b__1(IServiceProvider sp)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
   at Elastic.Apm.Extensions.Hosting.HostBuilderExtensions.<>c.<UseElasticApm>b__0_2(IServiceProvider sp)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)

Binding redirects don't seem to work in this instance, but upgrading dependencies in Elastic.Apm.Extensions.Hosting do. Is there a reason to keep compiling netstandard2.0 against version 2.1 of the Microsoft.Extensions.*?

Thanks for reporting this @ismaelhamed,

this will need some code change in the agent to be fixed, so I opened a GitHub issue about this: MissingMethodException on net48 with Elastic.Apm.Extensions.Hosting · Issue #1579 · elastic/apm-agent-dotnet · GitHub

Also thanks for the reproducer!

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.