MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.09k stars 21.14k forks source link

Error with DI for AppInsights #118621

Open Gamecock opened 6 months ago

Gamecock commented 6 months ago

error CS1061: 'IServiceCollection' does not contain a definition for 'ConfigureFunctionsApplicationInsights' and no accessible extension method 'ConfigureFunctionsApplicationInsights' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)

Here is my hostbuilder: var host = new HostBuilder() .ConfigureFunctionsWorkerDefaults() .ConfigureServices(s => { s.AddApplicationInsightsTelemetryWorkerService(); s.ConfigureFunctionsApplicationInsights(); s.AddLogging(); s.AddSingleton<IMyCustomInterface, MyCustomClass>(); }) .Build();

func start generates error CS1061: 'IServiceCollection' does not contain a definition for 'ConfigureFunctionsApplicationInsights' and no accessible extension method 'ConfigureFunctionsApplicationInsights' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)

Here are the relevant packages from my .csproject

`

<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues" Version="5.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.14.0" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />

`

Commenting out the call to ConfigureFunctionsApplicationInsights(); allows logging to work.

Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

RamanathanChinnappan-MSFT commented 6 months ago

@Gamecock Thanks for your feedback! We will investigate and update as appropriate.

JamesPScottPharm3r commented 6 months ago

I have the same issue here as well.

amalea commented 2 weeks ago

Hello,

@RamanathanChinnappan-MSFT and @ggailey777 could you please write down the solution? Is there any solution for the scenario above? Thanks!