Skip to content

ambiguous reference: AddApplicationInsightsTelemetryProcess #2972

@bossbast1

Description

@bossbast1

Describe the bug

Simple issue, in case we have common shared project used for function and main app (support logger classes and everything is in the base), Microsoft.ApplicationInsights.WorkerService and Microsoft.ApplicationInsights.AspNetCore conflicts on extension method in namespace Microsoft.Extensions.DependencyInjection method public static IServiceCollection AddApplicationInsightsTelemetryProcessor(this IServiceCollection services) where T : ITelemetryProcessor

Because you renamed AddApplicationInsightsTelemetry to AddApplicationInsightsTelemetryWorkerService, it makes sense to rename it also here.

To Reproduce

create a new .net 8 project (with latest versions of the libs) and include both these libraries
Microsoft.ApplicationInsights.WorkerService
Microsoft.ApplicationInsights.AspNetCore

sinple main

using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using SRChatBot.Common;

namespace BotOneFunctions
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var host = new HostBuilder()
                .ConfigureFunctionsWebApplication()
                .ConfigureServices(services =>
                {
                    services.AddApplicationInsightsTelemetryProcessor<ITelemetryProcessor>();
                })
                .Build();

            host.Run();
        }
    }
}

line:

services.AddApplicationInsightsTelemetryProcessor<ITelemetryProcessor>();

cannot be reasonable resolved in any way or form due to identical match from two libraries extenting exact same namespace

error

CS0121: The call is ambiguous between the following methods or properties: 'Microsoft.Extensions.DependencyInjection.ApplicationInsightsExtensions.AddApplicationInsightsTelemetryProcessor(Microsoft.Extensions.DependencyInjection.IServiceCollection)' and 'Microsoft.Extensions.DependencyInjection.ApplicationInsightsExtensions.AddApplicationInsightsTelemetryProcessor(Microsoft.Extensions.DependencyInjection.IServiceCollection)'

ugly fix

have dummy projects having just one of these dependencies that has one single extension file wrapping this method with different name.

eg.

using Microsoft.ApplicationInsights.Extensibility;

namespace Microsoft.Extensions.DependencyInjection
{
    public static class ApplicationInsightsExtensions
    {
        public static IServiceCollection AddApplicationInsightsTelemetryWorkerServiceProcessor<T>(this IServiceCollection services) where T : ITelemetryProcessor
        {
            return services.AddApplicationInsightsTelemetryProcessor<T>();
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions