title: "The given key was not present in the dictionary." error when ending dialog
body: <p>Im using botframework 4 (c#) together with Qnamaker to make a qnabot. I want the bot to go through give alternative questions if qna-service returns more than 1 answer. </p>
  
  <p>So I've made a dialog that does that. However then it goes through the steps and comes to the end and I call context.EndDialogAsync() it throws an "The given key was not present in the dictionary."-error.</p>
  
  <p>If I type something into the chat after this it will run the dialog-step over again and rinse and repeat. </p>
  
  <p>Anyone got any ideas what might be the issue? Im willing to the code I just don't know code that could be causing the error. </p>
  
  <p>Im trying to follow this example as much as possible: <a href="https://github.com/Microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/51.cafe-bot" rel="nofollow noreferrer">https://github.com/Microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/51.cafe-bot</a></p>
  
  <p>One difference is I couldn't get the bot to find my Dialog if I added it to in the MainDispatcher like they have done in the example (it couldn't find it). If I however added it to the "class" : IBot it worked. Could it be related?</p>
  
  <p>Appreciate any help or tips on how I can debug this, thanks!</p>
  
  <p>This sets up the dialog and all the steps in the waterfall works until I get to the last one and try to call EndDialogAsync.</p>
  
  <pre><code>        public OptionsDialog(IStatePropertyAccessor&lt;QnaProperty&gt; qnaAccessors, IEnumerable&lt;WaterfallStep&gt; steps = null, string dialogId = null)
          : base(Name)
      {
          QnAAccessor = qnaAccessors ?? throw new ArgumentNullException(nameof(qnaAccessors));
  
          var waterfallStepsOptions = new WaterfallStep[]
          {
              PromptQuestionAsync,
              WriteAnswerAsync,
              HelpfulResponseAsync,
          };
  
          AddDialog(new WaterfallDialog(WaterfallStepsName, waterfallStepsOptions));
          ChoicePrompt choice = new ChoicePrompt(QuestionPromptName);
          choice.Style = ListStyle.SuggestedAction;
          AddDialog(choice);
          AddDialog(new ChoicePrompt(HelpfulPromptName));
      }
  </code></pre>
  
  <p>Last waterfall step:</p>
  
  <pre><code>        private async Task&lt;DialogTurnResult&gt; HelpfulResponseAsync(WaterfallStepContext stepContext,
          CancellationToken cancellationToken)
      {
          var answer = (stepContext.Result as FoundChoice).Value;
          if (answer == "Yes")
          {
              await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Great!"), cancellationToken);
          }
          else
          {
              await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Maybe try rephrasing your question else here's a link to the documentation: LINK"), cancellationToken);
          }
  
          return await stepContext.EndDialogAsync(cancellationToken);
      }
  </code></pre>
  
  <p>The dialog thats starts this dialog looks like this:</p>
  
  <pre><code>        public MainDialog(BotServices services, ConversationState conversationState, string dialogId = null)
          : base(Name)
      {
          _services = services ?? throw new ArgumentNullException(nameof(services));
          _qnaAccessor = conversationState.CreateProperty&lt;QnaProperty&gt;(QnaProperty);
          _dialogAccessor = conversationState.CreateProperty&lt;DialogState&gt;(DialogProperty);
  
          _dialogs = new DialogSet(_dialogAccessor);
      }
  
      public override async Task&lt;DialogTurnResult&gt; BeginDialogAsync(DialogContext dc, object options = null,
          CancellationToken cancellationToken = default(CancellationToken))
      {
          var response = await _services.QnAServices[QnaConfiguration].GetAnswersAsync(dc.Context);
          var qnaProperty = await _qnaAccessor.GetAsync(dc.Context, () =&gt; new QnaProperty(response));
          //var qnaProperty = await _qnaAccessor.SetAsync(dc.Context, response, cancellationToken);
  
          if (response != null &amp;&amp; response.Length &gt; 1)
          {
              return await dc.BeginDialogAsync(OptionsDialog.Name, cancellationToken);
          }
          else if (response != null &amp;&amp; response.Length == 1)
          {
              await dc.Context.SendActivityAsync(response[0].Answer, cancellationToken: cancellationToken);
          }
          else
          {
              var msg = @"No QnA Maker answers were found.";
  
              await dc.Context.SendActivityAsync(msg, cancellationToken: cancellationToken);
          }
  
          return await dc.EndDialogAsync(cancellationToken);
      }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>It seems to work when I moved the logic from MainDispatcher Dialog to just the IBot class instead, so Im assuming maybe the issue is with finding the dialog when it's instantiated in the Ibot class instead of the maindialog. Maybe?</p>