question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DI cannot create BotFrameworkHttpAdapter (ambiguous constructor)

See original GitHub issue

Version

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:

  1. Clone the repo
  2. Change .TestBot so it is injecting BotFrameworkHttpAdapter instead of AdapterWithErrorHandler
  3. Connect from the emulator
  4. See error

Expected behavior

No error when injecting BotFrameworkHttpAdapter

Screenshots

n/a

Additional context

This seems important.

[bug]

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
EricDahlvangcommented, Jun 4, 2019

@EurekaChen Until a fix is committed, you can either comment out one of the constructors from BotFrameworkHttpAdapter, or specify one during di setup:

services.AddSingleton<IBotFrameworkHttpAdapter>(new BotFrameworkHttpAdapter(Configuration));
0reactions
johnataylorcommented, Jun 12, 2019

fixed in 4.4.5 and in master

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found