c# - System.Collections.Generic.KeyNotFoundException 与 Microsoft Bot Framework

标签 c# generics botframework azure-language-understanding

我正在使用 Microsoft Bot Framework 创建一个使用 LuisDialog 的非常简单的机器人。但是我不断收到 System.Collections.Generic.KeyNotFoundException。

这是我的 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;
}

这是我的对话:

[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);
    }
}

如果我使用旧版本的 Bot Framework,例如 3.0.0,我会收到以下错误: 500内部服务器错误 { "message": "发生错误。"

但是,如果我更新到最新的稳定版本 (3.2.1),则会收到以下类型为“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 "

完整的堆栈跟踪在这里:

http://pastebin.com/uLJF5fcV

我尝试在另一个解决方案上创建一个新项目,但我得到了同样的错误。我尝试通过 nuget 安装不同版本的 Bot Framework,但就像我之前所说的那样,无论哪种方式,我仍然会收到错误消息。到目前为止,我对 Bot Framework 的经验真的很少,所以我真的不知道还能尝试什么。

最佳答案

你能再试一次在 None 方法之上添加以下内容吗?

[LuisIntent("")]

您看到的错误通常发生在 LuisDialog 无法根据收到的消息解析要执行的方法(意图)时。

我怀疑有人提出了这个问题 here ,当 LuisDialog 寻找空意图时。

handler = this.handlerByIntent[string.Empty];

关于c# - System.Collections.Generic.KeyNotFoundException 与 Microsoft Bot Framework,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40110278/

相关文章:

c# - 将 Bot Framework Bot 作为 Azure Web 应用程序工作,突然没有配置更改,出现 SecurityTokenSignatureKeyNotFoundException : IDX10501

c# - 使用 OpenXML sdk 读取 excel 文件时遇到问题

c# - ASP.NET - 无法将更改从 GridView 保存到数据库

C#:重载具有不同类型参数的 LINQ 泛型方法

java - 泛型:为什么实现的集合返回一个对象而不是指定的类型?

node.js - Bot 框架 V4 Nodejs 聊天记录记录

c# - 为网站设置抑制警告

c# - 如何简化单元测试 DDD Value objects Equality with AutoFixture

swift - "Protocol ... can only be used as a generic constraint because it has Self or associated type requirements"是什么意思?

javascript - 如何在微软机器人框架中等待一个函数执行后再执行第二个函数?