microsoft / botbuilder-dotnet

Welcome to the Bot Framework SDK for .NET repository, which is the home for the libraries and packages that enable developers to build sophisticated bot applications using .NET.
https://github.com/Microsoft/botframework
MIT License
875 stars 484 forks source link

[Adaptive] Declarative adaptive dialogs (composer dialogs) do not work with non adaptive dialogs #3854

Closed vishwacsena closed 4 years ago

vishwacsena commented 4 years ago

Version

Latest master

Describe the bug

This sample used to work but I no longer know how to get a V4 waterfall/ custom dialog based bot to work with adaptive dialogs.

To Reproduce

  1. Run this sample
  2. Connect to bot in Emulator
  3. Answer first two prompts (first name, last name)
  4. The sample is set up to start the adaptive dialog as step 3. This fails.

Expected behavior

Bot works E2E.

[bug]

boydc2014 commented 4 years ago

Here is what i found after debugging into it.

The bot fails at getting languageGeneratorManager from dialogContext.Services image

line 41 result in null after excecution.

The reason LanguageGenratorManager is not dc.Services is that in DialogContext.Child.Get image

this samples hits line 114, and this Container.CreateChildrenContext won't inherit the Services from parent dc.

Underhood, line 114, will call CreateChildrenContext in ComponentDialog.CreateChildrenContext, inside, it will call createInnerDc, and calls new DialogContext which created a new dc with previous dc's Services.

The proper fix to me is to inherit Services in this case, either fix in CreateChildrenContext or inside CreateInnerDc will probably work.

During the debugging process, i found it's somewhat confusing how those dc are organized toghether. Especially when i saw

  1. this Get method is creating new context objects (is this an anti-patttern)?
  2. This GetChildrenContext is called by GetActiveDialogContext, and called by SendStateSnapshotTraceAsync, this make me feels very confusing about the lifecycle of dialogContext, seems like the dialogStack is already formed and run well, the dialogContext is created in a "SendingSnapshot" step, which i assume it should not create anything

cc @tomlm