System.Collections.Generic.KeyNotFoundException与Microsoft Bot Framework [英] System.Collections.Generic.KeyNotFoundException with Microsoft Bot Framework
问题描述
我正在使用Microsoft Bot Framework来使用LuisDialog创建一个非常简单的机器人。但是我不断收到一个System.Collections.Generic.KeyNotFoundException。
以下是我的控制器:
public async Task< HttpResponseMessage> Post([FromBody] Activity activity)
{
if(activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity,()=> new QuotesDialog());
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
返回响应;
}
这是我的对话框:
[Serializable]
[LuisModel(MyModelIdGoesHere,MySubscriptionKeyGoesHere)]
public class QuotesDialog:LuisDialog< object>
{
[LuisIntent(CheckQuote)]
public async任务CheckQuote(IDialogContext上下文,LuisResult结果)
{
await context.PostAsync(Hello you! );
context.Wait(MessageReceived);
[LuisIntent(None)]
public async任务无(IDialogContext上下文,LuisResult结果)
{
await context.PostAsync 我很抱歉,我没有明白。);
context.Wait(MessageReceived);
$ b如果我使用旧版本的Bot Framework,像3.0.0,我得到以下错误:
500 InternalServerError
{
消息:发生错误。然而,如果我更新到最新的稳定版本(3.2.1),那么我会得到类型为System.Collections.Generic的以下错误:
KeyNotFoundException:
异常:System.Collections.Generic.KeyNotFoundException:给定的
键在字典中不存在。
System.Collections.Generic.Dictionary2.get_Item(TKey key)at
Microsoft.Bot.Builder.Dialogs.LuisDialog
完整的堆栈跟踪如下:
我试着在另一个解决方案上创建一个新项目,但是我得到了同样的错误。我尝试通过nuget安装不同版本的Bot框架,但就像我之前说过的那样,这种或那种方式仍然会出现错误。到目前为止,我对Bot Framework的经验还很少,所以我真的不知道还有什么可以尝试的。
您再次尝试在None方法的基础上添加以下内容?
[LuisIntent()]
code>
您看到的错误通常是在LuisDialog无法根据收到的消息解析执行的方法(意图)时发生的。
我怀疑这个问题正在被提出这里,当LuisDialog寻找空的意图。
handler = this.handlerByIntent [string.Empty];
I am using the Microsoft Bot Framework to create a really simple bot using a LuisDialog. However I keep getting a System.Collections.Generic.KeyNotFoundException.
Here's my controller:
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity, () => new QuotesDialog());
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
Here's my dialog:
[Serializable]
[LuisModel("MyModelIdGoesHere", "MySubscriptionKeyGoesHere")]
public class QuotesDialog : LuisDialog<object>
{
[LuisIntent("CheckQuote")]
public async Task CheckQuote(IDialogContext context, LuisResult result)
{
await context.PostAsync("Hello you!");
context.Wait(MessageReceived);
}
[LuisIntent("None")]
public async Task None(IDialogContext context, LuisResult result)
{
await context.PostAsync("I'm sorry. I didn't get that.");
context.Wait(MessageReceived);
}
}
If I use an older version of the Bot Framework, like 3.0.0, I get the following error: 500 InternalServerError { "message": "An error has occurred." }
However if I update to the latest stable version (3.2.1) then I get the following error of the type "System.Collections.Generic.KeyNotFoundException":
"Exception: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. at System.Collections.Generic.Dictionary2.get_Item(TKey key) at Microsoft.Bot.Builder.Dialogs.LuisDialog "
The full stack trace is here:
I tried create a new project on another solution, but I get the same error. I tried install different versions of the Bot Framework via nuget but like I said previously, one way or another I still get an error. I have really little experience with the Bot Framework so far, so I don't really know what else to try.
Can you try again adding the following on top of the None method?
[LuisIntent("")]
The error that you are seeing is usually happening when the LuisDialog cannot resolve the method (intent) to execute based on the message received.
I suspect the issue is being raised here, when the LuisDialog looks for the empty intent.
handler = this.handlerByIntent[string.Empty];
这篇关于System.Collections.Generic.KeyNotFoundException与Microsoft Bot Framework的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!