Skip to content

Multiple constructors for HttpClientRequestAdapter breaks DI #655

@greuelpirat

Description

@greuelpirat

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Nuget tool

Client library/SDK language

Csharp

Describe the bug

Starting with 1.21.0 the call builder.Services.AddHttpClient<IRequestAdapter, HttpClientRequestAdapter>() throws following exception:

System.InvalidOperationException: Multiple constructors accepting all given argument types have been found in type 'Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter'. There should only be one applicable constructor.

Expected behavior

There should be no exception, DI should work out of the box like before.

How to reproduce

using Microsoft.Kiota.Abstractions;
using Microsoft.Kiota.Http.HttpClientLibrary;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHttpClient<IRequestAdapter, HttpClientRequestAdapter>();

var app = builder.Build();

_ = app.Services.GetRequiredService<IRequestAdapter>(); // crash

Open API description file

No response

Kiota Version

1.21.0

Latest Kiota version known to work for scenario above?(Not required)

1.20.1

Known Workarounds

downgrade

Configuration

No response

Debug output

Click to expand log ``` fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1] An unhandled exception has occurred while executing the request. System.InvalidOperationException: Multiple constructors accepting all given argument types have been found in type 'Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter'. There should only be one applicable constructor. at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.TryFindMatchingConstructor(Type instanceType, Type[] argumentTypes, ConstructorInfo& matchingConstructor, Nullable`1[]& parameterMap) at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.FindApplicableConstructor(Type instanceType, Type[] argumentTypes, ConstructorInfoEx[] constructors, ConstructorInfo& matchingConstructor, Nullable`1[]& matchingParameterMap) at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateFactoryInternal(Type instanceType, Type[] argumentTypes, ParameterExpression& provider, ParameterExpression& argumentArray, Expression& factoryExpressionBody) at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateFactory(Type instanceType, Type[] argumentTypes) at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) at Microsoft.Extensions.Http.DefaultTypedHttpClientFactory`1.Cache.get_Activator() at Microsoft.Extensions.Http.DefaultTypedHttpClientFactory`1.CreateClient(HttpClient httpClient) at Microsoft.Extensions.DependencyInjection.HttpClientBuilderExtensions.AddTransientHelper[TClient,TImplementation](IServiceProvider s, IHttpClientBuilder builder) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context) ```

Other information

No response

Metadata

Metadata

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

Status
Done ✔️

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions