I'm new to bot developing and I'm trying to build from the Microsoft Documentation guides, and play around a little, but I've hit a stump quickly, and I can't figure out why...
I have these 2 Dialogs:
[Serializable]
public class RootDialog : IDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
var message = await result;
if (message.Text.ToLower().Contains("count"))
{
context.Call(new CountDialog(), this.ResumeAfterEchoDialog);
} else
{
await context.PostAsync("You said: " + message.Text);
}
context.Wait(MessageReceivedAsync);
}
private async Task ResumeAfterEchoDialog(IDialogContext context, IAwaitable<int> result)
{
var resultFromEcho = await result;
await context.PostAsync($"Back from count dialog, with final count: {resultFromEcho}");
context.Wait(this.MessageReceivedAsync);
}
}
And:
[System.Serializable]
public class CountDialog : IDialog<int>
{
protected int count = 1;
public async Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
}
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
{
var message = await argument;
if (message.Text.ToLower().Contains("finish"))
{
PromptDialog.Confirm(
context,
AfterFinishAsync,
"Are you sure you want to finish counting?",
"Didn't get that!",
promptStyle: PromptStyle.None);
}
else
{
await context.PostAsync($"{this.count++}: You said {message.Text}");
context.Wait(MessageReceivedAsync);
}
}
public async Task AfterFinishAsync(IDialogContext context, IAwaitable<bool> argument)
{
var confirm = await argument;
if (confirm)
{
context.Done(count);
}
else
{
await context.PostAsync("Did not finish counting.");
context.Wait(MessageReceivedAsync);
}
}
}
The idea is simply so that if the user says count, it goes to the CountDialog, counts the times the user says something, and if he says finish, goes back to the RootDialog, returning the final count number.
But when I test it in the Bot Framework Channel Emulator I get two exception messages like this right away:
Exception: Object reference not set to an instance of an object.
[File of type 'text/plain']
content": " at Bot_Application_Demo.Dialogs.RootDialog.<MessageReceivedAsync>d__1.MoveNext() in C:\\Users\\MiguelSilva(1110770)\\Source\\Repos\\Bot Application Demo\\Bot Application Demo\\Dialogs\\RootDialog.cs:line 21\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume`1.<Rest>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Internals.Fibers.Wait`2.<Microsoft-Bot-Builder-Internals-Fibers-IWait<C>-PollAsync>d__19.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Internals.Fibers.Frame`1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop<C>-PollAsync>d__9.MoveNext()\r\n--- End of stack trace from previous location where exception was t....
I can guess it's probably something simple and obvious but I can't really find out why this is happening.