【发布时间】:2020-04-21 12:36:27
【问题描述】:
在运行我的 Core Bot C# 示例后,我得到了 System.AggregateException。
在Startup.cs我添加的类如下:
services.AddSingleton<ChitChatRecognizer>();
识别器类如下所示:
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.AI.QnA;
using Microsoft.Bot.Schema;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace CoreBot
{
public class ChitChatRecognizer : ActivityHandler
{
private readonly IConfiguration _configuration;
private readonly ILogger<ChitChatRecognizer> _logger;
private readonly IHttpClientFactory _httpClientFactory;
public ChitChatRecognizer(IConfiguration configuration, ILogger<ChitChatRecognizer> logger, IHttpClientFactory httpClientFactory)
{
_configuration = configuration;
_logger = logger;
_httpClientFactory = httpClientFactory;
}
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
var httpClient = _httpClientFactory.CreateClient();
var qnaMaker = new QnAMaker(new QnAMakerEndpoint
{
KnowledgeBaseId = _configuration["QnAKnowledgebaseId"],
EndpointKey = _configuration["QnAEndpointKey"],
Host = _configuration["QnAEndpointHostName"]
},
null,
httpClient);
_logger.LogInformation("Calling QnA Maker");
var options = new QnAMakerOptions { Top = 1 };
// The actual call to the QnA Maker service.
var response = await qnaMaker.GetAnswersAsync(turnContext, options);
if (response != null && response.Length > 0)
{
await turnContext.SendActivityAsync(MessageFactory.Text(response[0].Answer), cancellationToken);
}
else
{
await turnContext.SendActivityAsync(MessageFactory.Text("No QnA Maker answers were found."), cancellationToken);
}
}
}
}
我什至还没有使用该类,但我什至无法在没有错误的情况下启动我的程序。 我该怎么办?
错误代码:
“某些服务无法构建(验证服务描述符'ServiceType:CoreBot.ChitChatRecognizer Lifetime:Singleton ImplementationType:CoreBot.ChitChatRecognizer'时出错:无法解析类型'System.Net.Http.IHttpClientFactory'的服务'尝试激活“CoreBot.ChitChatRecognizer”时。)(验证服务描述符“ServiceType:Microsoft.BotBuilderSamples.Dialogs.MainDialog Lifetime:Singleton ImplementationType:Microsoft.BotBuilderSamples.Dialogs.MainDialog”时出错:无法解析“System”类型的服务.Net.Http.IHttpClientFactory',同时尝试激活'CoreBot.ChitChatRecognizer'。)(验证服务描述符时出错'ServiceType:Microsoft.Bot.Builder.IBot Lifetime:Transient ImplementationType:Microsoft.BotBuilderSamples.Bots.DialogAndWelcomeBot`1 [ Microsoft.BotBuilderSamples.Dialogs.MainDialog]':尝试激活时无法解析“System.Net.Http.IHttpClientFactory”类型的服务'CoreBot.ChitChatRecognizer'.)"
【问题讨论】:
标签: botframework chatbot azure-language-understanding qnamaker