question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReplaceDialogAsync doesn't change ActiveDialog

See original GitHub issue

Version

4.4.4

Describe the bug

After calling ReplaceDialogAsync, if we use an AdaptiveCard with a submit button, the OnEventAsync method should show, on our ActiveDialog property, the value of the new Dialog, but it shows the old Dialog.

For example, you have your MainDialog, which calls StartDialogAsync(nameof(FAQDialog)). On your FAQDialog, you call ReplaceDialogAsync(nameof(AnotherDialog)). If you use an AdaptiveCard with a Submit button on the “AnotherDialog”, the event caught on the MainDialog (with the function “OnEventAsync”) should show the ActiveDialog as “AnotherDialog”, but shows as “FAQDialog”.

To Reproduce

Steps to reproduce the behavior:

  1. Create a Virtual Assistant
  2. Use ReplaceDialogAsync on a Dialog A to Dialog B
  3. Insert an Adaptive Card with a Submit button on Dialog B
  4. Click the submit button
  5. Check the value of the ActiveDialog on the MainDialog

Expected behavior

Active Dialog should have the value of the dialog which replaced the old one.

[bug]

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
garyprettycommented, May 28, 2019

@tiagodenoronha I hit this issue some time ago.

If I have understood this correctly (I have spent quite a bit of time looking into the code around this tonight), the ActiveDialog value is set when the inner dialog context state is re-hydrated when calling ContinueDialogAsync on the context, which only currently happens within the VA solution when continuing the current dialog (when a MessageActivity is received - https://github.com/microsoft/botframework-solutions/blob/c4ecbadc99d211f8f029c9da7d4899d5de4b287f/templates/Customer-Support-Template/CustomerSupportTemplate/Dialogs/Shared/RouterDialog.cs#L29). Because you are receiving an event, this gets handled within the MainDialog, which means your ActiveDialog will be showing as ‘MainDialog’ at this stage.

I am not totally clear at this point if this is actually bug, or simply a side effect of not continuing the current dialog, which the team may be able to clear up. However, until then I thought it might be useful to show you what I did to workaround this, which was by checking the state value of the ActiveDialog (MainDialog) instance for child dialogs on the stack. I realise it is not the nicest / cleanest solution, but hopefully it helps.


            if (dc.ActiveDialog != null)
            {
                var dialogId = dc.ActiveDialog.Id;
                var currentDialogState = dc.ActiveDialog.State.ContainsKey("dialogs") ? (DialogState)dc.ActiveDialog.State["dialogs"] : null;

                while (currentDialogState != null)
                {
                    if (currentDialogState.DialogStack != null && currentDialogState.DialogStack.Any() && currentDialogState.DialogStack.Count == 1)
                    {
                        dialogId = currentDialogState.DialogStack.First().Id;

                        currentDialogState = currentDialogState.DialogStack.First().State.ContainsKey("dialogs")
                            ? (DialogState)currentDialogState.DialogStack.First().State["dialogs"] : null;
                    }
                    else
                    {
                        currentDialogState = null;
                    }
                }
}

0reactions
tiagodenoronhacommented, Nov 16, 2019

Could it be that it’s the Adaptive Cards that are returning to MainDialog? It might not be related to the ReplaceDialogAsync…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Botframework V4: ID of active dialog not changing even ...
I need to do a condition depending on the Id of the active dialog something like this. var dc = await _dialogs.CreateContextAsync(turnContext); ...
Read more >
DialogContext.ReplaceDialogAsync(String, Object ...
Starts a new dialog and replaces on the stack the currently active dialog with the new one. ... ReplaceDialogAsync(String, Object, CancellationToken) Method.
Read more >
DialogContext class
Requests the active dialog to re-prompt the user for input. Constructor Details. DialogContext(DialogSet, DialogContext, DialogState). Creates an new instance ...
Read more >
Source File Press 'n' to go to next uncovered line, 'b' for ...
Gets the set of dialogs that can be called from this context. ... Gets the cached <see cref="DialogInstance"/> of the active dialog on...
Read more >
Exam AI-102 topic 5 question 14 discussion
You need to ensure that you can dispose of the property when the last active dialog ends. Which scope should you assign to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found