Cabuxa.Mapache
Cabuxa.Mapache

Reputation: 771

Stack is empty error when calling context.Done in child dialog

I have a LuisDialog which makes a forward to another LuisDialog in the "None" intent as some kind of fallback:

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

The method executed in MyChildDialog is like this:

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

When the context.Done() is executed, emulator shows an error: "Stack is empty". But, how can it be empty if forward adds the dialog to the stack?

Upvotes: 1

Views: 301

Answers (1)

Dave Smits
Dave Smits

Reputation: 1889

Make sure you have a handler for what to do when the MyChildDialog is fininshed

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

Upvotes: 1

Related Questions