Emanuele Leoni

Emanuele Leoni

  • NA
  • 139
  • 16.9k

Error: Stack is empty exception in Bot Framework

Mar 20 2018 5:57 AM
Hi,
I created a chatbot by Bot Framework and I implemented a Reset option in order to delete the conversation e grant to the user to begin a new conversation.
  1. // MessageController.cs
  2. public async Task Post([FromBody]Activity activity)  
  3. {  
  4.   await Conversation.SendAsync(activity, () => new RootDialog().DefaultIfException());  
  5.   return Request.CreateResponse(HttpStatusCode.OK);  <- Stack is empty Exception
  6. // RootDialog.cs
  1. private void ShowMenuOptions(IDialogContext context)      
  2. {    
  3.     List<string> optionList = new List<string>();    
  4.     optionList.Add("Info");    
  5.     optionList.Add("Support");    
  6.     optionList.Add("Reset");    
  7.     
  8.     string prompt ="How can I help you?";    
  9.     
  10.     PromptDialog.Choice(context, this.OnOptionSelected, (IEnumerable<string>)optionList, prompt, retry, attempts);    
  11. }    
  12.         
  13. private async Task OnOptionSelected(IDialogContext context, IAwaitable<string> result) 
  14. {    
  15.     try    
  16.     {    
  17.         string optionSelected = await result;    
  18.     
  19.         switch (optionSelected)    
  20.         {    
  21.             case "Reset":    
  22.                 context.Reset();    
  23.                 context.ConversationData.Clear();    
  24.                 context.PrivateConversationData.Clear();    
  25.                 context.UserData.Clear();    
  26.                 break;    
  27.         }    
  28.     }    
  29. }    
When an user chooses reset option, the bot answers with "Sorry, my bot code is having an issue."
Debugging the code I see that the exception triggers after context.Reset().
 
Can anybody help me and solve it? 

Answers (1)