在子对话框中调用context.Done时,堆栈为空错误

时间:2017-07-04 06:06:18

标签: c# botframework

我有一个LuisDialog,它将前往另一个LuisDialog中的#34;无"意图作为某种后备:

[LuisIntent("None")]
public async Task None(IDialogContext context, IAwaitable<IMessageActivity> message, LuisResult result)
{
    var luisService = new LuisService(new LuisModelAttribute("XXX", "XXX"));
    await context.Forward(new MyChildDialog(luisService), null, await message);

    context.Wait(MessageReceived);
}

MyChildDialog中执行的方法如下:

[LuisIntent("myLuisIntent")]
public async Task MyLuisIntent(IDialogContext context, LuisResult result)
{
    await context.PostAsync("Hi!");
    context.Done(0);
}

执行context.Done()时,模拟器显示错误:&#34; Stack为空&#34;。但是,如果将对话框添加到堆栈中,它怎么能为空?

1 个答案:

答案 0 :(得分:1)

确保您有一个处理程序,以便在完成MyChildDialog时可以执行的操作

    [LuisIntent("None")]
    public async Task None(IDialogContext context, IAwaitable<IMessageActivity> message, LuisResult result)
    {
        var luisService = new LuisService(new LuisModelAttribute("XXX", "XXX"));
        await context.Forward(new MyChildDialog(luisService), WaitForMessageResume, await message);

        context.Wait(MessageReceived);
    }

    private Task WaitForMessageResume(IDialogContext context, IAwaitable<object> result)
    {
        context.Wait(MessageReceived);
        return Task.CompletedTask;
    }