DI cannot create BotFrameworkHttpAdapter (ambiguous constructor)
See original GitHub issueVersion
master branch from repo
Describe the bug
services.AddSingleton<IBotFrameworkHttpAdapter, BotFrameworkHttpAdapter>();
Results in:
System.InvalidOperationException: Unable to activate type 'Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter'. The following constructors are ambiguous:
Void .ctor(Microsoft.Bot.Connector.Authentication.ICredentialProvider, Microsoft.Bot.Connector.Authentication.IChannelProvider, Microsoft.Extensions.Logging.ILogger`1[Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter])
Void .ctor(Microsoft.Extensions.Configuration.IConfiguration, Microsoft.Extensions.Logging.ILogger`1[Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter])
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(Type serviceType, Type implementationType, CallSiteChain callSiteChain)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor descriptor, Type serviceType, CallSiteChain callSiteChain)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(Type serviceType, CallSiteChain callSiteChain)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type serviceType, CallSiteChain callSiteChain)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.CreateServiceAccessor(Type serviceType)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
at lambda_method(Closure , IServiceProvider , Object[] )
at Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider.<>c__DisplayClass4_0.<CreateActivator>b__0(ControllerContext controllerContext)
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass5_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
To Reproduce
Steps to reproduce the behavior:
- Clone the repo
- Change .TestBot so it is injecting BotFrameworkHttpAdapter instead of AdapterWithErrorHandler
- Connect from the emulator
- See error
Expected behavior
No error when injecting BotFrameworkHttpAdapter
Screenshots
n/a
Additional context
This seems important.
[bug]
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:7 (5 by maintainers)
Top Results From Across the Web
.NET Core Dependency Injection giving "Ambiguous ...
It seems strange that the dependency injection mechanism considers the constructors to be ambiguous when IHttpClientFactory and HttpClient ...
Read more >How to solve ambiguous constructors when trying to start ...
1 Answer. This has been solved. The root issue was a Dependency Configuration that was trying to load some scoped items into the...
Read more >AmbiguousMatchException Constructor (System.Reflection)
Initializes a new instance of the AmbiguousMatchException class with an empty message string and the root cause exception set to null . public: ......
Read more >Ambiguous constructors - ASP.NET Core Video Tutorial
In this video, learn what ambiguous constructors are and how to deal with them in dependency injection. This is important as you need...
Read more >Ambiguous call error during compilation when explicit ...
In this case compiler takes both f() functions but it should notice, that first is not available and it should generate code with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@EurekaChen Until a fix is committed, you can either comment out one of the constructors from BotFrameworkHttpAdapter, or specify one during di setup:
fixed in 4.4.5 and in master