Start fails with "Unable to resolve service for type 'ChannelServiceHandler' while attempting to activate 'ChannelServiceController'.)'
See original GitHub issueVersion
4.7.0
Describe the bug
I’m writing a ASP.NET Core 3.1 C# app where I use several packages of the BotBuilder SDK. What works fine with SDK 4.6.3 now fails with 4.7.0 with the following exception:
System.AggregateException: 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Microsoft.Bot.Builder.Integration.AspNet.Core.ChannelServiceController Lifetime: Transient ImplementationType: Microsoft.Bot.Builder.Integration.AspNet.Core.ChannelServiceController': Unable to resolve service for type 'Microsoft.Bot.Builder.ChannelServiceHandler' while attempting to activate 'Microsoft.Bot.Builder.Integration.AspNet.Core.ChannelServiceController'.)'
Exception 1/2
InvalidOperationException: Error while validating the service descriptor 'ServiceType: Microsoft.Bot.Builder.Integration.AspNet.Core.ChannelServiceController Lifetime: Transient ImplementationType: Microsoft.Bot.Builder.Integration.AspNet.Core.ChannelServiceController': Unable to resolve service for type 'Microsoft.Bot.Builder.ChannelServiceHandler' while attempting to activate 'Microsoft.Bot.Builder.Integration.AspNet.Core.ChannelServiceController'.
Exception 2/2
InvalidOperationException: Unable to resolve service for type 'Microsoft.Bot.Builder.ChannelServiceHandler' while attempting to activate 'Microsoft.Bot.Builder.Integration.AspNet.Core.ChannelServiceController'.
This exception was originally thrown at this call stack:
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(System.Type, System.Type, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain, System.Reflection.ParameterInfo[], bool)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(Microsoft.Extensions.DependencyInjection.ServiceLookup.ResultCache, System.Type, System.Type, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(Microsoft.Extensions.DependencyInjection.ServiceDescriptor, System.Type, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain, int)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(Microsoft.Extensions.DependencyInjection.ServiceDescriptor, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain)
Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.ValidateService(Microsoft.Extensions.DependencyInjection.ServiceDescriptor)
Expected behavior
The application starts fine.
Additional context
Is it possible that this is related to this PR? https://github.com/microsoft/botbuilder-dotnet/pull/3038/files
I also hope that I can build a project to reproduce the error. It currently also only fails when compiling a debug version and running it with the ASP Environment set to Development
for whatever reason.
Is there anything I possible did wrong or a cache I need to clear? Like I said, the same code runs fine with version 4.6.3 of all Microsoft.Bot.* packages.
[bug]
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Dependency Injection error: Unable to resolve service for ...
c# - Dependency Injection error: Unable to resolve service for type while attempting to activate, while class is registered - Stack Overflow.
Read more >Unable to resolve service for type while attempting ...
A C# code example that shows how to correct the ASP.NET Core Dependency Injection error: 'Unable to resolve service for type while attempting...
Read more >How to Solve Unable to Resolve Service for a Type
In this article, we will explain what the error "unable to resolve service for type" means, what causes it, and how to fix...
Read more >Unable to resolve service for type '' while attempting to ...
What am I missing? What I have tried: I have tried rearranging the order of services in the container but the error still...
Read more >ASP.Net Core API Error (Unable to resolve service for type ' ...
ASP.Net Core API Error (Unable to resolve service for type 'TapAPI.Models.TodoContext' while attempting to activate 'TapAPI.Controllers.
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
Hi @sibbl, we accelerated the fix for this issue and we just released a fix, if you update your project to use 4.7.2 it should work now.
Thanks for the feedback and detailed repro project.
Hi @sibbl
With Bot Builder 4.7, we introduced a ChannelServiceController. This is being discovered by dependency injection when calling
.AddControllersAsServices()
As a workaround, it is possible to exclude the integration library from discovery with something like:
Or by using a custom
ControllerFeatureProvider
to filter out theChannelServiceController
We will raise this issue with the team, and come up with a better long term solution.