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

**URL:** <https://discuss.elastic.co/t/elastic-apm-extensions-hosting-doesnt-work-with-net48-if-you-already-have-a-dependency-on-microsoft-extensions-dependencyinjection-version-5-0/289403>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [November 17, 2021, 7:36am UTC](https://discuss.elastic.co/t/elastic-apm-extensions-hosting-doesnt-work-with-net48-if-you-already-have-a-dependency-on-microsoft-extensions-dependencyinjection-version-5-0/289403 "2021-11-17T07:36:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ismaelhamed](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ismaelhamed/32/97203_2.png) [@ismaelhamed](https://discuss.elastic.co/u/ismaelhamed)\
**Post date:** [November 17, 2021, 7:36am UTC](https://discuss.elastic.co/t/elastic-apm-extensions-hosting-doesnt-work-with-net48-if-you-already-have-a-dependency-on-microsoft-extensions-dependencyinjection-version-5-0/289403/1 "2021-11-17T07:36:59Z")

</div>

I've created a small [Gist](https://gist.github.com/ismaelhamed/fcc18ba7ffed9c31cddaa4cc98aefdda) 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:

```auto
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.*`?

---

<div class="post-metadata">

**Author:** ![GregKalapos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregkalapos/32/37205_2.png) [@GregKalapos](https://discuss.elastic.co/u/GregKalapos)\
**Post date:** [November 30, 2021, 4:34pm UTC](https://discuss.elastic.co/t/elastic-apm-extensions-hosting-doesnt-work-with-net48-if-you-already-have-a-dependency-on-microsoft-extensions-dependencyinjection-version-5-0/289403/2 "2021-11-30T16:34:47Z")

</div>

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](https://github.com/elastic/apm-agent-dotnet/issues/1579)

Also thanks for the reproducer!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 21, 2021, 12:35pm UTC](https://discuss.elastic.co/t/elastic-apm-extensions-hosting-doesnt-work-with-net48-if-you-already-have-a-dependency-on-microsoft-extensions-dependencyinjection-version-5-0/289403/3 "2021-12-21T12:35:22Z")

</div>

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