0

its working perfectly in Bot framework Emulator but showing error in Teams on that point

if(Dialog != null)
{
  await Dialog.RunAsync( turnContext, ConversationState.CreateProperty<DialogState>("DialogState"), cancellationToken);
  //Logger.LogInformation("Running dialog with Message Activity.");
}  

Here is the code:

protected override async Task OnMessageActivityAsync(
  ITurnContext<IMessageActivity> turnContext, 
  CancellationToken cancellationToken)
{
  // Run the Dialog with the new message Activity.
  if (Dialog == null)
    throw new ArgumentNullException("Dialog is null");
  if (ConversationState == null)
    throw new ArgumentNullException("ConversationState is null");
  if (cancellationToken == null)
    throw new ArgumentNullException("cancellationToken is null");

  if (turnContext == null)
    throw new ArgumentNullException("turnContext is null");
  if(Dialog != null)
  {
    //error
    await Dialog.RunAsync( 
      turnContext, 
      ConversationState.CreateProperty<DialogState>("DialogState"), 
      cancellationToken);
    //Logger.LogInformation("Running dialog with Message Activity.");
  }         
}
Lance U. Matthews
  • 15,725
  • 6
  • 48
  • 68
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jun 27 '22 at 08:43
  • Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Lance U. Matthews Jun 27 '22 at 19:21
  • As an aside, the lone/first `string` parameter in the `ArgumentNullException` constructors specifies the parameter name; the semantics of that exception already communicate that something "is null", the only piece of information that's missing is _which_ parameter. So, you'd rewrite that as `throw new ArgumentNullException("turnContext");` or, to stay consistent even after a parameter rename, `throw new ArgumentNullException(nameof(turnContext));`. `Dialog` and `ConversationState` aren't parameters, so `throw`ing an `InvalidOperationException` or just an `Exception` would be more appropriate. – Lance U. Matthews Jun 27 '22 at 19:31

1 Answers1

0

This exception means that something is null. It would seem that at least one of the variables in that call (assuming your first code block is where the exception occurs) is null. You can try debugging locally with ngrok to run the bot through a local debugger but interact with it through Teams.

You can step through and watch the bot execute a command sent from Teams. Follow the execution till the point where the exception occurs, and check what variable is null. Once you know which variable is null, you can fix the error.

(As an aside, it might help to give dialogs more descriptive names than just Dialog)

AP01
  • 820
  • 1
  • 2
  • 8
  • 1
    If an answer more specific than "something is null" can't be given (and I didn't believe it can with the lack of information in the question) then that's where marking as a duplicate of [the canonical question on the matter](https://stackoverflow.com/q/4660142/150605) is appropriate since those answers cover all those issues. – Lance U. Matthews Jun 27 '22 at 19:21