Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sibbl opened this issue Jan 14, 2020 · 3 comments

Comments

@sibbl
Copy link

@sibbl sibbl commented Jan 14, 2020

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]

@dmvtech

This comment has been minimized.

Copy link

@dmvtech dmvtech commented Jan 14, 2020

hi @sibbl

I would be interested in a repro as well. What botbuilder packages are you using? Are you starting from a visx project or a sample?

It currently also only fails when compiling a debug version and running it with the ASP Environment set to Development for whatever reason

That is interesting. Is all this testing, etc done locally? (running bot locally and testing with emulator)

I don't believe this has anything to do with 3.1 or the linked issue, but we'll see. If we can reproduce it, that will help. (If you're able to throw a repro up on a repo, even better).

@sibbl

This comment has been minimized.

Copy link
Author

@sibbl sibbl commented Jan 15, 2020

@dmvtech thanks for your quick reply! Please find a sample project here:
BotBuilderDemoProject.zip

You can reproduce it either by

  1. opening the solution and running it in Visual Studio
  2. or by running the reproduce.ps1 which sets the asp.net env to "dev" and uses dotnet for building and running it.

While fiddling together the project, I found out that services.AddMvc().AddControllersAsServices(); causes the trouble. Changing the line to services.AddMvc(); fixes it. Then the whole bot should behave just like the EchoBot from the samples repo.

Possibly there's a circular dependency due to some changes in the ChannelServiceController?

One more thing: there's the special fact that we're using a common library ("UniBot" in the sample) with reusable dialogs, services, and also a common BotStartup implementation. This project is then referenced and used by other projects ("ImmoBot" in this sample). I was not able to reproduce the issue using a single project.

@EricDahlvang

This comment has been minimized.

Copy link
Collaborator

@EricDahlvang EricDahlvang commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.