I followed the sample codes on Microsoft/BotBuilder with Microsoft.Bot.Connector.AspNetCore 3.6.0-alpha
When I send a message to bot, there was an error meesage like this :
The service provider instance was not register. Please call RegisterServiceProvider before using ServiceProvider.Instance.
which happened on var appCredentials = new MicrosoftAppCredentials(this._configuration);
Here are my packages in .csproj file.
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
<PackageReference Include="Microsoft.Bot.Connector.AspNetCore" Version="3.6.0-alpha" />
<PackageReference Include="Microsoft.Bot.Connector.AspNetCore.Mvc" Version="3.6.0-alpha" />
<PackageReference Include="Microsoft.Bot.Connector.Common" Version="3.6.0-alpha" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
</ItemGroup>
Other codes are all similar with the sample codes on Microsoft/BotBuilder. But my code runs fine with Microsoft.Bot.Connector 3.5.1-alpha.
PS. I posted my codes in stackoverflow as well.
Just call services.UseBotConnector() on ConfigureServices method of your Startup class.
This method is provided by Microsoft.Bot.Connector.BotServiceProviderExtensions extension class localized on assembly Microsoft.Bot.Connector.AspNetCore (the respective package have the same name).
@luizcarlosfaria , thank you for the reply.
But I cannot find the namespace or package of Microsoft.Bot.Connector.BotServiceProviderExtensions.
Is the package available in nuget? Thank you so much!
If you are using ASP.NET, you should be able to register the provider with this snippet before initializing the
MicrosoftAppCredentials class.
if (!ServiceProvider.IsRegistered)
{
ServiceProvider.RegisterServiceProvider(new BotServiceProvider());
};
If you are using ASP.NET Core, you need this in your startup:
services.UseBotConnector();
Also check this issue for more details #2590
@KarateJB add package Microsoft.Bot.Connector.AspNetCore to your project references.
It works! Thank you so much, @luizcarlosfaria and @andreesteve!