question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to resolve service for type 'Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration'

See original GitHub issue

I am trying to run my Azure Function locally in Visual Studio 2019. I am relying on AppInsights + dependency injection to get an instance of TelemetryConfiguration, so I can construct a TelementryClient for logging.

When I run my function locally, I run into this error,

Unable to resolve service for type 'Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration'

I tried the suggestions in related issues (#4682 and https://github.com/MicrosoftDocs/azure-docs/issues/35181), however, I had no luck. Namely, I tried installing downgraded versions of AppInsights nuget package. See repro steps for full details.

Edit: I tried running in Azure instead of just locally, and it fails there as well.

Investigative information

  • Timestamp: N/A (local run)
  • Function App version: 2.0
  • Function App name: DocfxPipeline
  • Function name: CategoryHydrateFunction
  • Invocation ID: NA (local run)
  • Region: NA (local run)

Repro steps

  1. Create a function app in Visual Studio 2019. I created a TimerTrigger function.
  2. Install Application Insights nuget package if not done so already. Package “Microsoft.ApplicationInsights” and v2.12.0 (I have also tried versions 2.9.1, 2.10.0 and 2.11.0 as suggested by the aforementioned issues)
  3. In your function constructor, add a parameter for TelemetryConfiguration similar to
public MyFunction( TelemetryConfiguration telemetryConfiguration ) { ... }
  1. Add an entry for APPINSIGHTS_INSTRUMENTATIONKEY environment variable to local.settings.json
  2. Run the function via F5

Here is a complete picture of my function project’s nuget dependencies:

    <PackageReference Include="Microsoft.ApplicationInsights" Version="2.12.0" />
    <PackageReference Include="Microsoft.Azure.ServiceBus" Version="4.1.1" />
    <PackageReference Include="Microsoft.Azure.Services.AppAuthentication" Version="1.3.1" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="3.0.5" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.10" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.1.3" />
    <PackageReference Include="Microsoft.Identity.Client" Version="4.7.1" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.2" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <PackageReference Include="RestSharp" Version="106.10.0" />

Expected behavior

After performing step 5, I expect the function to start and my break point in the constructor to be hit.

Actual behavior

Azure Functions Core Tools terminal shows error

“Microsoft.Extensions.DependencyInjection.Abstractions: Unable to resolve service for type ‘Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration’ while attempting to activate ‘DocfxPipelineFunctions.CategoryHydrationFunction’.”

Here is the complete transcript from the terminal in case it helps:

Azure Functions Core Tools (2.7.1948 Commit hash: 29a0626ded3ae99c4111f66763f27bb9fb564103)
Function Runtime Version: 2.0.12888.0
[1/23/2020 10:23:54 PM] Building host: startup suppressed: 'False', configuration suppressed: 'False', startup operation id: '845b6b4e-bed0-4160-af4b-77fa76030f85'
[1/23/2020 10:23:55 PM] Reading host configuration file 'C:\Users\sclin\Repos\PIE-AECore-EngineeringHub\docfxpipeline\DocfxPipelineFunctions\bin\Debug\netcoreapp2.1\host.json'
[1/23/2020 10:23:55 PM] Host configuration file read:
[1/23/2020 10:23:55 PM] {
[1/23/2020 10:23:55 PM]   "version": "2.0"
[1/23/2020 10:23:55 PM] }
[1/23/2020 10:23:55 PM] Reading functions metadata
[1/23/2020 10:23:55 PM] 1 functions found
[1/23/2020 10:23:55 PM] Loading startup extension 'AzureStorage'
[1/23/2020 10:23:55 PM] Loaded extension 'AzureStorage' (3.0.10.0)
[1/23/2020 10:23:57 PM] Initializing Warmup Extension.
[1/23/2020 10:23:57 PM] Initializing Host. OperationId: '845b6b4e-bed0-4160-af4b-77fa76030f85'.
[1/23/2020 10:23:57 PM] Host initialization: ConsecutiveErrors=0, StartupCount=1, OperationId=845b6b4e-bed0-4160-af4b-77fa76030f85
[1/23/2020 10:23:57 PM] ApplicationInsightsLoggerOptions
[1/23/2020 10:23:57 PM] {
[1/23/2020 10:23:57 PM]   "SamplingSettings": {
[1/23/2020 10:23:57 PM]     "EvaluationInterval": "00:00:15",
[1/23/2020 10:23:57 PM]     "InitialSamplingPercentage": 100.0,
[1/23/2020 10:23:57 PM]     "MaxSamplingPercentage": 100.0,
[1/23/2020 10:23:57 PM]     "MaxTelemetryItemsPerSecond": 20.0,
[1/23/2020 10:23:57 PM]     "MinSamplingPercentage": 0.1,
[1/23/2020 10:23:57 PM]     "MovingAverageRatio": 0.25,
[1/23/2020 10:23:57 PM]     "SamplingPercentageDecreaseTimeout": "00:02:00",
[1/23/2020 10:23:57 PM]     "SamplingPercentageIncreaseTimeout": "00:15:00"
[1/23/2020 10:23:57 PM]   },
[1/23/2020 10:23:57 PM]   "SamplingExcludedTypes": null,
[1/23/2020 10:23:57 PM]   "SamplingIncludedTypes": null,
[1/23/2020 10:23:57 PM]   "SnapshotConfiguration": null,
[1/23/2020 10:23:57 PM]   "EnablePerformanceCountersCollection": true,
[1/23/2020 10:23:57 PM]   "HttpAutoCollectionOptions": {
[1/23/2020 10:23:57 PM]     "EnableHttpTriggerExtendedInfoCollection": true,
[1/23/2020 10:23:57 PM]     "EnableW3CDistributedTracing": true,
[1/23/2020 10:23:57 PM]     "EnableResponseHeaderInjection": true
[1/23/2020 10:23:57 PM]   },
[1/23/2020 10:23:57 PM]   "LiveMetricsInitializationDelay": "00:00:15",
[1/23/2020 10:23:57 PM]   "EnableLiveMetrics": true,
[1/23/2020 10:23:57 PM]   "EnableDependencyTracking": true
[1/23/2020 10:23:57 PM] }
[1/23/2020 10:23:57 PM] LoggerFilterOptions
[1/23/2020 10:23:57 PM] {
[1/23/2020 10:23:57 PM]   "MinLevel": "None",
[1/23/2020 10:23:57 PM]   "Rules": [
[1/23/2020 10:23:57 PM]     {
[1/23/2020 10:23:57 PM]       "ProviderName": null,
[1/23/2020 10:23:57 PM]       "CategoryName": null,
[1/23/2020 10:23:57 PM]       "LogLevel": null,
[1/23/2020 10:23:57 PM]       "Filter": "<AddFilter>b__0"
[1/23/2020 10:23:57 PM]     },
[1/23/2020 10:23:57 PM]     {
[1/23/2020 10:23:57 PM]       "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[1/23/2020 10:23:57 PM]       "CategoryName": null,
[1/23/2020 10:23:57 PM]       "LogLevel": "None",
[1/23/2020 10:23:57 PM]       "Filter": null
[1/23/2020 10:23:57 PM]     },
[1/23/2020 10:23:57 PM]     {
[1/23/2020 10:23:57 PM]       "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[1/23/2020 10:23:57 PM]       "CategoryName": null,
[1/23/2020 10:23:57 PM]       "LogLevel": null,
[1/23/2020 10:23:57 PM]       "Filter": "<AddFilter>b__0"
[1/23/2020 10:23:57 PM]     },
[1/23/2020 10:23:57 PM]     {
[1/23/2020 10:23:57 PM]       "ProviderName": "Microsoft.Azure.WebJobs.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider",
[1/23/2020 10:23:57 PM]       "CategoryName": null,
[1/23/2020 10:23:57 PM]       "LogLevel": "Trace",
[1/23/2020 10:23:57 PM]       "Filter": null
[1/23/2020 10:23:57 PM]     }
[1/23/2020 10:23:57 PM]   ]
[1/23/2020 10:23:57 PM] }
[1/23/2020 10:23:57 PM] LoggerFilterOptions
[1/23/2020 10:23:57 PM] {
[1/23/2020 10:23:57 PM]   "MinLevel": "None",
[1/23/2020 10:23:57 PM]   "Rules": [
[1/23/2020 10:23:57 PM]     {
[1/23/2020 10:23:57 PM]       "ProviderName": null,
[1/23/2020 10:23:57 PM]       "CategoryName": null,
[1/23/2020 10:23:57 PM]       "LogLevel": null,
[1/23/2020 10:23:57 PM]       "Filter": "<AddFilter>b__0"
[1/23/2020 10:23:57 PM]     },
[1/23/2020 10:23:57 PM]     {
[1/23/2020 10:23:57 PM]       "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[1/23/2020 10:23:57 PM]       "CategoryName": null,
[1/23/2020 10:23:57 PM]       "LogLevel": "None",
[1/23/2020 10:23:57 PM]       "Filter": null
[1/23/2020 10:23:57 PM]     },
[1/23/2020 10:23:57 PM]     {
[1/23/2020 10:23:57 PM]       "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[1/23/2020 10:23:57 PM]       "CategoryName": null,
[1/23/2020 10:23:57 PM]       "LogLevel": null,
[1/23/2020 10:23:57 PM]       "Filter": "<AddFilter>b__0"
[1/23/2020 10:23:57 PM]     },
[1/23/2020 10:23:57 PM]     {
[1/23/2020 10:23:57 PM]       "ProviderName": "Microsoft.Azure.WebJobs.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider",
[1/23/2020 10:23:57 PM]       "CategoryName": null,
[1/23/2020 10:23:57 PM]       "LogLevel": "Trace",
[1/23/2020 10:23:57 PM]       "Filter": null
[1/23/2020 10:23:57 PM]     }
[1/23/2020 10:23:57 PM]   ]
[1/23/2020 10:23:57 PM] }
[1/23/2020 10:23:57 PM] FunctionResultAggregatorOptions
[1/23/2020 10:23:57 PM] {
[1/23/2020 10:23:57 PM]   "BatchSize": 1000,
[1/23/2020 10:23:57 PM]   "FlushTimeout": "00:00:30",
[1/23/2020 10:23:57 PM]   "IsEnabled": true
[1/23/2020 10:23:57 PM] }
[1/23/2020 10:23:57 PM] SingletonOptions
[1/23/2020 10:23:57 PM] {
[1/23/2020 10:23:57 PM]   "LockPeriod": "00:00:15",
[1/23/2020 10:23:57 PM]   "ListenerLockPeriod": "00:00:15",
[1/23/2020 10:23:57 PM]   "LockAcquisitionTimeout": "10675199.02:48:05.4775807",
[1/23/2020 10:23:57 PM]   "LockAcquisitionPollingInterval": "00:00:05",
[1/23/2020 10:23:57 PM]   "ListenerLockRecoveryPollingInterval": "00:01:00"
[1/23/2020 10:23:57 PM] }
[1/23/2020 10:23:57 PM] QueuesOptions
[1/23/2020 10:23:57 PM] {
[1/23/2020 10:23:57 PM]   "BatchSize": 16,
[1/23/2020 10:23:57 PM]   "NewBatchThreshold": 8,
[1/23/2020 10:23:57 PM]   "MaxPollingInterval": "00:00:02",
[1/23/2020 10:23:57 PM]   "MaxDequeueCount": 5,
[1/23/2020 10:23:58 PM]   "VisibilityTimeout": "00:00:00"
[1/23/2020 10:23:58 PM] }
[1/23/2020 10:23:58 PM] BlobsOptions
[1/23/2020 10:23:58 PM] {
[1/23/2020 10:23:58 PM]   "CentralizedPoisonQueue": false
[1/23/2020 10:23:58 PM] }
[1/23/2020 10:23:58 PM] HttpOptions
[1/23/2020 10:23:58 PM] {
[1/23/2020 10:23:58 PM]   "DynamicThrottlesEnabled": false,
[1/23/2020 10:23:58 PM]   "MaxConcurrentRequests": -1,
[1/23/2020 10:23:58 PM]   "MaxOutstandingRequests": -1,
[1/23/2020 10:23:58 PM]   "RoutePrefix": "api"
[1/23/2020 10:23:58 PM] }
[1/23/2020 10:23:58 PM] Starting JobHost
[1/23/2020 10:23:58 PM] Starting Host (HostId=desktopajf7vh8-1642830398, InstanceId=d833cc48-b5c5-4ed7-9279-77221091176a, Version=2.0.12888.0, ProcessId=16928, AppDomainId=1, InDebugMode=False, InDiagnosticMode=False, FunctionsExtensionVersion=(null))
[1/23/2020 10:23:58 PM] Loading functions metadata
[1/23/2020 10:23:58 PM] 1 functions loaded
[1/23/2020 10:23:58 PM] Generating 1 job function(s)
[1/23/2020 10:23:58 PM] Found the following functions:
[1/23/2020 10:23:58 PM] DocfxPipelineFunctions.CategoryHydrationFunction.Run
[1/23/2020 10:23:58 PM]
[1/23/2020 10:23:58 PM] Initializing function HTTP routes
[1/23/2020 10:23:58 PM] No HTTP routes mapped
[1/23/2020 10:23:58 PM]
[1/23/2020 10:23:58 PM] Host initialized (601ms)
[1/23/2020 10:24:00 PM] Executed 'CategoryHydrationFunction' (Failed, Id=386b999e-85bd-4759-85e8-fe092ea50db9)
[1/23/2020 10:24:00 PM] Microsoft.Extensions.DependencyInjection.Abstractions: Unable to resolve service for type 'Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration' while attempting to activate 'DocfxPipelineFunctions.CategoryHydrationFunction'.
[1/23/2020 10:24:00 PM] The next 5 occurrences of the 'CategoryHydrationFunction' schedule (Cron: '0 * * * * *') will be:
[1/23/2020 10:24:00 PM] 01/23/2020 14:25:00-08:00 (01/23/2020 22:25:00Z)
[1/23/2020 10:24:00 PM] 01/23/2020 14:26:00-08:00 (01/23/2020 22:26:00Z)
[1/23/2020 10:24:00 PM] 01/23/2020 14:27:00-08:00 (01/23/2020 22:27:00Z)
[1/23/2020 10:24:00 PM] 01/23/2020 14:28:00-08:00 (01/23/2020 22:28:00Z)
[1/23/2020 10:24:00 PM] 01/23/2020 14:29:00-08:00 (01/23/2020 22:29:00Z)
[1/23/2020 10:24:00 PM]
[1/23/2020 10:24:00 PM] Host started (2155ms)
[1/23/2020 10:24:00 PM] Job host started
[1/23/2020 10:24:00 PM] Executed 'CategoryHydrationFunction' (Failed, Id=fc93494f-bf55-4ed1-9355-4a1d1e8ebab0)
[1/23/2020 10:24:00 PM] Microsoft.Extensions.DependencyInjection.Abstractions: Unable to resolve service for type 'Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration' while attempting to activate 'DocfxPipelineFunctions.CategoryHydrationFunction'.
Hosting environment: Production
Content root path: C:\Users\sclin\Repos\PIE-AECore-EngineeringHub\docfxpipeline\DocfxPipelineFunctions\bin\Debug\netcoreapp2.1
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.

Related information

  • Programming language: C#
  • Bindings used: [TimerTrigger( "0 */1 * * * *" )]TimerInfo timer

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
scott-lincommented, Feb 6, 2020

I confirmed Brett’s workaround works.

1reaction
brettsamcommented, Feb 5, 2020

I believe there’s two issues you’re running into but we should be able to get you running:

  1. Add <SkipFunctionsDepsCopy>true</SkipFunctionsDepsCopy> to your project file. This will prevent a deps.json file from being deployed and redirecting the App Insights reference.
  2. Reference 2.0.11 (or earlier) of the ApplicationInsights package.

Make sure to rebuild or fully clean as the deps.json file may hang around if you don’t.

The good news is that both of these restrictions will go away soon. This PR has fixed the issue (I just did some testing again to maks sure): https://github.com/Azure/azure-functions-host/pull/5551. You can see that for some other issues that are also impacted by this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

asp.net core - Unable to resolve service for type 'Microsoft. ...
I have migrate my Web project from RC1 to RC2, but I'm having this error: Unable to resolve service for type 'Microsoft.ApplicationInsights.
Read more >
Application Insights for ASP.NET Core applications
Monitor ASP.NET Core web applications for availability, performance, and usage.
Read more >
Discussion on: Develop Azure Functions using .NET Core 3.1
Abstractions: Unable to resolve service for type 'Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration'.
Read more >
How to use dependency inject for TelemetryConfiguration ...
Abstractions : Unable to resolve service for type 'Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration' while attempting to activate 'OMS.VA.
Read more >
C# Azure TelemetryClient will leak memory if not implemented ...
I noticed that my classic .net web application would leak memory after I implemented metrics for some background tasks.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found