Search code examples
asp.net-coreazure-application-insightsasp.net-core-3.1

Unable to resolve service for type 'Microsoft.AspNetCore.Hosting.IHostingEnvironment


I'm in the middle of upgrading from netcore2.2 to netcore3.1

I have a line that calls to services.AddApplicationInsightsTelemetry(); which results in the below

System.InvalidOperationException: 'Unable to resolve service for type 'Microsoft.AspNetCore.Hosting.IHostingEnvironment' while attempting to activate 'Microsoft.AspNetCore.Hosting.DefaultApplicationInsightsServiceConfigureOptions'.'

I know this is related to an on-going issue (https://github.com/microsoft/ApplicationInsights-dotnet/issues/1869), but that doesn't help me resolve the issue.

Is there a known work-around?


Solution

  • I'd udpated everything, turns out it was a test mocking out IHostingEnvironment