BotBuilder-MicrosoftTeams-dotnet icon indicating copy to clipboard operation
BotBuilder-MicrosoftTeams-dotnet copied to clipboard

[Bug]"Getting started" code causes an error in Startup.cs.

Open osamum opened this issue 5 years ago • 8 comments

Describe the bug When "Getting started" code add to Startup.cs and run BOT, an error occurs. Error message is the following :  "Object reference not set to an instance of an object."

Repro steps is the following:

  1. Create EchoBot with Bot template V4. (C#, Visual Studio 2017)
  2. Install the EchoBot to Microsoft Teams.
  3. Add the "Getting started" code add to services.AddBot<MyFirstBotBot> in Startup.cs.
  4. Add the "Getting started" code add to OnTurnAsync in the ***bot.cs.
  5. Set breakpoint to the following code in Startup.cs.   logger.LogError($"Exception caught : {exception}");
  6. Run EchoBot project.
  7. Chat to Bot using Microsoft Teams. 8.Error causes and the code does stop at the breakpoint.

SDK Version Microsoft.Bot.Builder 4.3.2 Microsoft.Bot.Builder.Integration.AspNet.Core 4.3.2 Microsoft.Bot.Builder.Teams 4.0.0-beta1 Microsoft.Bot.Configuration 4.3.2 Microsoft.Bot.Connector 4.3.2 Microsoft.Bot.Schema 4.3.2

.Net Version .Net Core 2.1

Expected behavior The errors are caught in options.OnTurnError in Startup.cs.

Screenshots

Additional context Hosts endpoints using ngrok.

osamum avatar Mar 17 '19 05:03 osamum

Can you try the TeamsEchoBot sample in this repo?

RamjotSingh avatar Mar 17 '19 05:03 RamjotSingh

In my environment, a Microsoft.Bot.Builder dependency error occurred and the project could not be run. https://github.com/OfficeDev/BotBuilder-MicrosoftTeams-dotnet/tree/master/CSharp/Samples/Microsoft.Bot.Builder.Teams.TeamEchoBot

osamum avatar Mar 17 '19 16:03 osamum

What is the error you hit while running sample?

RamjotSingh avatar Mar 18 '19 00:03 RamjotSingh

After that, I deleted the solution folder and re-copy new solutions and resolved the issue. Now TeamEchoBot project dose normally compiling. However, When TeamEchoBot run display 404 page in web browser. When I connect to the http://localhost:65307/api/message then display 405 page in web browser. I worked the following steps:

  1. open Microsoft.Bot.Builder.Teams.sln with Visual Studio 2017.
  2. Rebuild the solution.
  3. Click to the Microsoft.Bot.Builder.Teams.TeamEchoBot project in solution explorer.
  4. Press [F5] key

Is correct my run work for TeamEchoBot project?

osamum avatar Mar 18 '19 05:03 osamum

I am guessing you are doing GET when trying to display the page in web browser. Ignore the 404. And try hitting the bot from Microsoft Teams. Also before you run the sample, make sure you added your BotAppId and Password to appSettings.json

RamjotSingh avatar Mar 18 '19 09:03 RamjotSingh

Did this work for you?

RamjotSingh avatar May 03 '19 16:05 RamjotSingh

Having same issue. Trying to add Teams middleware to an existing working bot. Steps:

  1. Add Nuget
  2. Add the "Getting started" code in Startup.cs.

Now when I hit my first line in my bot (CreateContextAsync), it fails with "Object reference not set to an instance of an object"

 public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
        {
            var dialogContext = await this.dialogs.CreateContextAsync(turnContext, cancellationToken);

I'm using blobstorage instead of MemoryStorage, but otherwise can't see any other changes from my bot compared to the examples, so what could be wrong here?

  var storageContainer = string.IsNullOrWhiteSpace(blobStorageConfig.Container) ? DefaultBotContainer : blobStorageConfig.Container;
   IStorage dataStore = new Microsoft.Bot.Builder.Azure.AzureBlobStorage(blobStorageConfig.ConnectionString, storageContainer);

   var conversationState = new TeamSpecificConversationState(dataStore);
   options.State.Add(conversationState);

tnsholding avatar May 05 '19 09:05 tnsholding

@tnsholding What are the package versions you are using?

RamjotSingh avatar May 07 '19 09:05 RamjotSingh