azure-docs icon indicating copy to clipboard operation
azure-docs copied to clipboard

Error with DI for AppInsights

Open Gamecock opened this issue 1 year ago • 4 comments

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

<ItemGroup> <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.19.0" /> <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" /> </ItemGroup>

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.

Gamecock avatar Jan 08 '24 14:01 Gamecock