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.

Start fails with "Unable to resolve service for type 'ChannelServiceHandler' while attempting to activate 'ChannelServiceController'.)'

See original GitHub issue

Version

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:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
gabogcommented, Jan 23, 2020

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.

1reaction
EricDahlvangcommented, Jan 15, 2020

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:

public virtual void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().ConfigureApplicationPartManager(manager=> 
                {
                    var botAssemblyPart = manager.ApplicationParts.FirstOrDefault(a => a.Name == typeof(ChannelServiceController).Assembly.GetName().Name);
                    manager.ApplicationParts.Remove(botAssemblyPart);
                })
            .AddControllersAsServices();
            
 
            services.AddSingleton<IBotFrameworkHttpAdapter, BotFrameworkHttpAdapter>();
 
            services.AddTransient<IBot, GenericBot>();
        }

Or by using a custom ControllerFeatureProvider to filter out the ChannelServiceController

We will raise this issue with the team, and come up with a better long term solution.

Read more comments on GitHub >

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

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