Botframework-sdk: [.NET SDK] 401 Unauthorized in 3.15.2.2

Created on 12 Jun 2018  ·  57Comments  ·  Source: microsoft/botframework-sdk

Bot Info

  • SDK Platform: .Net
  • SDK Version: 3.15.2.2

If you are experiencing this issue please post the following details, do not just post "Me too" with no details

  1. Frequency - How often is this happening? Every message? Randomly and how often ex. 1 out of 10 messages
  2. What channels is this happening on, is it working on any channels?
  3. Stack trace
  4. Deployment where is this happening - Local testing? Azure? Both?

if not locally

  1. Type of bot Functions bot? Web App bot?
  2. Is there any relevant info in app insights?
  3. Timestamp and conversation ID when this occurs?
  1. Is the bot using the default state service? What state store is the bot using?

Most helpful comment

This bug should have the highest priority.

All 57 comments

Frequency - Every 2-3 hrs.
What channels is this happening on, is it working on any channels? -> We are available only on teams and it's happening on teams.

Stack trace ->
unauthorized_stacktrace.txt

Deployment where is this happening - Azure

  1. Type of bot Functions bot? Web App bot? -> Web App Bot [Microsoft App Id : 094e061b-7682-4bdd-8524-d35359dfcf67]
  2. Is there any relevant info in app insights? -> Looks like it happened while executing Conversation.SendAsync
  3. Timestamp and conversation ID when this occurs? 6‎/‎12‎/‎2018‎ ‎2‎:‎23‎:‎49‎ ‎PM and a:1TYwQEwOlQGyKFSLEamY_DS-bsmtgzZ_YhoIMPRyaBZvKufM1YHUrkj1LtMPGJvwfsEF9gmO4BkEGP70XFmKy5Y-o60Oe5W6bSMHHrfz3KxYOYTqYai0rjPUeV1tX6ILD

1) 2-3 hours and only one message, following messages would be processed without any issues, can appears in background job logs (perform connector.Conversations.SendToConversation((Activity)message);).
2) Telegram Group Chat
3) StackTrace.txt
4) Azure
5) Web App (Actualy don't understand this question)
6) Disabled right now
7) 2018-06-12 12:57:38.4186 and -230902953

Every 2-5 hours, the first message
Webchat, Facebook
at Microsoft.Bot.Connector.Conversations.d__9.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.Connector.ConversationsExtensions.d__9.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.Dialogs.Internals.AlwaysSendDirect_BotToUser.d__4.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\BotToUser.cs:line 124\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.InputHintQueue.d__4.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\BotToUser.cs:line 184\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.AutoInputHint_BotToUser.d__3.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\BotToUser.cs:line 146\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.MapToChannelData_BotToUser.d__3.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\BotToUser.cs:line 295\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.LogBotToUser.d__4.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\IActivityLogger.cs:line 131\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.DialogContext.d__12.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogContext.cs:line 87\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.Extensions.d__14.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\IDialogContext.cs:line 150\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.Sample.SimpleEchoBot.EchoDialog.d__2.MoveNext() in C:\SW\dotnet\projects\arcofel Messenger\ArcofelMessengerBot-src\Dialogs\EchoDialog.cs:line 38\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.ThunkResume1.d__5.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogTask.cs:line 164\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.Wait2.d__19.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Fibers\Wait.cs:line 0\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.Frame1.-PollAsync>d__9.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Fibers\Fiber.cs:line 0\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.Fiber1.d__16.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Fibers\Fiber.cs:line 0\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at Microsoft.Bot.Builder.Internals.Fibers.Wait2.Microsoft.Bot.Builder.Internals.Fibers.IAwaiter.GetResult() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Fibers\Wait.cs:line 378\r\n at Microsoft.Bot.Builder.Dialogs.Chain.LoopDialog1.d__3.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\Chain.cs:line 752\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.ThunkResume1.d__5.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogTask.cs:line 164\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.Wait2.d__19.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Fibers\Wait.cs:line 0\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.Frame1.-PollAsync>d__9.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Fibers\Fiber.cs:line 0\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.Fiber1.d__16.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Fibers\Fiber.cs:line 244\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.d__23.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogTask.cs:line 321\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.ReactiveDialogTask.d__3.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogTask.cs:line 376\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.ScoringEventLoop`1.d__5.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\ScoringEventLoop.cs:line 87\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.EventLoopDialogTask.d__3.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogTask.cs:line 435\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.SetAmbientThreadCulture.d__3.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\PostToBot.cs:line 103\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.QueueDrainingDialogTask.d__4.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogTask.cs:line 455\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.PersistentDialogTask.d__3.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogTask.cs:line 481\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.d__3.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogTask.cs:line 485\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.ExceptionTranslationDialogTask.d__2.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogTask.cs:line 403\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.SerializeByConversation.d__4.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\PostToBot.cs:line 129\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 arcofel_UniversalBot.Dialogs.CustomPostUnhandledExceptionToUser.d__5.MoveNext() in C:\SW\dotnet\projects\arcofel Messenger\ArcofelMessengerBot-src\Dialogs\CustomPostUnhandledExceptionToUser.cs:line 37
Azure
Web App bot
the same information 401 Unauthorized
{
"type": "message",
"timestamp": "2018-06-12T15:01:02.7672977+00:00",
"localTimestamp": "2018-06-12T15:01:02.7672977+00:00",
"serviceUrl": "https://facebook.botframework.com",
"channelId": "facebook",
"from": {
"id": "1898523587053781",
"name": "ArcofelMessengerBot"
},
"conversation": {
"isGroup": false,
"id": "1664395866958984-1898523587053781"
},
"recipient": {
"id": "1664395866958984",
"name": "Kevin Port"
},
"text": "34: You said HI",
"attachments": [],
"entities": [],
"replyToId": "mid.$cAAbkQRGlcGxqJcjiZ1j9IOZ8ZKBv"
}
https://facebook.botframework.com/v3/conversations/1664395866958984-1898523587053781/activities/mid.%24cAAbkQRGlcGxqJcjiZ1j9IOZ8ZKBv

Default Echo bot with CustomPostUnhandledExceptionToUser

@ujwalakhaire @prorok-kane @kevinport Are your bots using the default state service? If not, what state store are they using?

@EricDahlvang now InMemoryDataStore.

@EricDahlvang TableBotDataStore, like the default azure bot template

Hi,

I am using TableBotDataStore but would like to know if global.asax.cs below is right:

using Autofac;
using Autofac.Integration.WebApi;
using Microsoft.Bot.Builder.Azure;
using Microsoft.Bot.Builder.Dialogs.Internals;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Web.Http;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using Microsoft.WindowsAzure.Storage;
using System.Configuration;

namespace botzapprices2018
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
{
var config = GlobalConfiguration.Configuration;
Conversation.UpdateContainer(
builder =>
{
builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly()));

                    var store = new TableBotDataStore(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
                    builder.Register(c => store)
                        .Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
                        .AsSelf()
                        .SingleInstance();

                    // Register your Web API controllers.
                    builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
                    builder.RegisterWebApiFilterProvider(config);

                });

            config.DependencyResolver = new AutofacWebApiDependencyResolver(Conversation.Container);
        }

        // WebApiConfig stuff
        GlobalConfiguration.Configure(config =>
        {
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        });
    }

    public static ILifetimeScope FindContainer()
    {
        var config = GlobalConfiguration.Configuration;
        var resolver = (AutofacWebApiDependencyResolver)config.DependencyResolver;
        return resolver.Container;
    }
}

}

From the current Azure Template

`using Autofac;
using System.Web.Http;
using System.Configuration;
using System.Reflection;
using Microsoft.Bot.Builder.Azure;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Dialogs.Internals;
using Microsoft.Bot.Connector;
using arcofel_UniversalBot.Dialogs;

namespace SimpleEchoBot
{
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
// Bot Storage: This is a great spot to register the private state storage for your bot.
// We provide adapters for Azure Table, CosmosDb, SQL Azure, or you can implement your own!
// For samples and documentation, see: https://github.com/Microsoft/BotBuilder-Azure

        Conversation.UpdateContainer(
            builder =>
            {
                builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly()));

                // Using Azure Table Storage
                var store = new TableBotDataStore(ConfigurationManager.AppSettings["AzureWebJobsStorage"]); // requires Microsoft.BotBuilder.Azure Nuget package 

                // To use CosmosDb or InMemory storage instead of the default table storage, uncomment the corresponding line below
                // var store = new DocumentDbBotDataStore("cosmos db uri", "cosmos db key"); // requires Microsoft.BotBuilder.Azure Nuget package 
                // var store = new InMemoryDataStore(); // volatile in-memory store

                builder.Register(c => store)
                    .Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
                    .AsSelf()
                    .SingleInstance();

                builder
 .RegisterType<CustomPostUnhandledExceptionToUser>()
 .Keyed<IPostToBot>(typeof(PostUnhandledExceptionToUser));

            });
        GlobalConfiguration.Configure(WebApiConfig.Register);
    }
}

}
`

@EricDahlvang We use TableBotDataStore

Hi Kevin,

Thanks for your reply. I have already tried the global.asax.cs from the Azure template and others.

I am using the one from https://github.com/Microsoft/BotBuilder-Azure/blob/master/CSharp/Samples/AzureTable/Global.asax.cs .

May someone tell which one is better ?

Hi, we recently started to get this issue and reported in the msdn forums and after a few replies they mentioned this issue.

  • Frequency. In almost every message.
  • What channels is this happening on? We have WebChat and DirectLine only and this is happening in both.
  • Type of bot Functions bot? Web App Bot deployed in our server and registered on Azure (Bot Channel Registration)
  • Is there any relevant info in app insights? The website https://webchat.botframework.com was down last Friday for a few hours, but when it went up we started to get this issue.
  • Timestamp and conversation ID when this occurs? Since last friday, near midday.
  • What state store is the bot using? TableBotDataStore

Same here. Lib 3.15.2.2

  • Frequency - Only the first time after a longer disconnect to the bot. All calls afterwards are good, even when restarting the underlaying WebApp of the Bot.
  • We use MS Teams Channel and Direct Line - Seen on Direct Line. Not sure if also on MS Teams Channel as there is less traffic.
  • Deployment where is this happening - Till now no chance to reproduce this locally. Happens on Azure and of multiple environments (dev, staging, prod)

Recently I got an update to the Nuget Packages System.IdentityModel.Tokens.Jwt and Microsoft.IdentityModel.Tokens (version 5.2.4 for both) and in my case the issue seems to be fixed and I don't have the Unauthorized response.

I will keep testing and checking in case something's wrong, but at first it seem resolved.

Hi,

Even with 5.2.4 update it fails.

It was the first time in two days. I use web app, sdk 3.15.2.2, the fail was in Telegram, at 2018-06-27 05:23:34.777, with service url https://telegram.botframework.com and conversation id 371758214. Less than 2 seconds later the bot was able to send a message successfully.

It was the first message I was trying to send to this user in reply to its "/start" message .

Hi,

we are getting this issue as well

  • Frequency: it is very randomly no frequency pattern so far (only 50 messages over the last 30 days out of thousands)
  • channels: this is happening in directline channel
  • Deployment: this is happening with an azure API app service
  • StateService: Cosmos Document Store
  • Stack Trace:
Microsoft.Bot.Connector.ErrorResponseException:
   at Microsoft.Bot.Connector.Conversations+<ReplyToActivityWithHttpMessagesAsync>d__8.MoveNext (Microsoft.Bot.Connector, Version=3.14.0.7, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at Microsoft.Bot.Connector.ConversationsExtensions+<ReplyToActivityAsync>d__7.MoveNext (Microsoft.Bot.Connector, Version=3.14.0.7, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at ZainOmniBot.Controllers.BotController+<sendReply>d__8.MoveNext (ZainOmniBot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullZainOmniBot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: C:\Users\admin\Desktop\Projects\zain_prototype\ZainOmniBot\Controllers\BotControllers\BotController.csZainOmniBot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: 312)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at ZainOmniBot.ZainBotController+<Greeting>d__19.MoveNext (ZainOmniBot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullZainOmniBot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: C:\Users\admin\Desktop\Projects\zain_prototype\ZainOmniBot\Controllers\BotControllers\ZainBotController.csZainOmniBot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: 383)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at ZainOmniBot.ZainBotController+<NonLoggedIn>d__11.MoveNext (ZainOmniBot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullZainOmniBot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: C:\Users\admin\Desktop\Projects\zain_prototype\ZainOmniBot\Controllers\BotControllers\ZainBotController.csZainOmniBot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: 159)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at ZainOmniBot.Controllers.BotController+<routeActivity>d__7.MoveNext (ZainOmniBot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullZainOmniBot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: C:\Users\admin\Desktop\Projects\zain_prototype\ZainOmniBot\Controllers\BotControllers\BotController.csZainOmniBot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: 297)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at ZainOmniBot.Controllers.BotController+<Post>d__5.MoveNext (ZainOmniBot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullZainOmniBot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: C:\Users\admin\Desktop\Projects\zain_prototype\ZainOmniBot\Controllers\BotControllers\BotController.csZainOmniBot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: 67)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at System.Threading.Tasks.TaskHelpersExtensions+<CastToObject>d__1`1.MoveNext (System.Web.Http, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at System.Web.Http.Controllers.ApiControllerActionInvoker+<InvokeActionAsyncCore>d__1.MoveNext (System.Web.Http, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at System.Web.Http.Filters.ActionFilterAttribute+<CallOnActionExecutedAsync>d__6.MoveNext (System.Web.Http, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
   at System.Web.Http.Filters.ActionFilterAttribute+<CallOnActionExecutedAsync>d__6.MoveNext (System.Web.Http, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at System.Web.Http.Filters.ActionFilterAttribute+<ExecuteActionFilterAsyncCore>d__5.MoveNext (System.Web.Http, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at System.Web.Http.Controllers.ActionFilterResult+<ExecuteAsync>d__5.MoveNext (System.Web.Http, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
   at System.Web.Http.Dispatcher.HttpControllerDispatcher+<SendAsync>d__15.MoveNext (System.Web.Http, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)

Hi,
Can confirm this issue.

Frequency - Randomly. Mostly as soon as a user connects and bot send a greeting message.
Out bot is deployed on directline channel.
The bot is using Table storage for state service.

var store = new TableBotDataStore(ConfigurationManager.ConnectionStrings["StateStorageConnectionString"].ConnectionString);

             // Register bot data store to enable state management using database

                builder.Register(c => store)
                    .Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
                    .AsSelf()
                    .SingleInstance();

                builder.Register(c => new CachingBotDataStore(store,
                         CachingBotDataStoreConsistencyPolicy.LastWriteWins))
                         .As<IBotDataStore<BotData>>()
                         .AsSelf()
                         .InstancePerLifetimeScope();

Some conversation id and timestamps :

| Conversation ID | Timestamps |
| ------------- | ------------- |
| CAQe8wxkmtmAWdfshvwzYS | 2018-06-27T00:44:57.6233173+00:00 |
| 7KUUlIOqur3tYzBZXr34S | 2018-06-26T01:54:10.118322+00:00 |
| CKhvy5zMKmqCD9pI4g6sjF | 2018-06-26T08:06:04.5426479+00:00 |
|HPEw084s3j1A3ER61hKOoy | 2018-06-25T18:06:15.8236009+00:00 |

Stack trace of 1 of the id can be found at this pastebin url

@ujwalakhaire @prorok-kane @kevinport @JonesAbramoff @NioZero @BenAffleckIsBatman @Lepird @Kartik1607
We have released a new package 3.15.2.3 that we believe addresses this issue. Please let us know if you are still experiencing this issue after upgrading.

Hi,

I updated all nuget packages and got the same error.

Channel: Slack
service URL: https://slack.botframework.com
Conversation ID: BBFSMK2LA:TBGJN8ZHC:DBFPQMFKM
Time: 2018-06-28 16:34:15.023 UTC−03:00

It was the first message.

I am using Global.asax.cs from https://github.com/Microsoft/BotBuilder-Azure/blob/master/CSharp/Samples/AzureTable/Global.asax.cs as posted earlier above.

Would you recommend to change it ?

@JonesAbramoff have you only seen this on the first message? I notice you said this was the case on 2 posts in this thread. If this is the case, what you are seeing might be unrelated and will need to be investigated separately.

Hi Jason,

I don´t know if my global.asax.cs is related to the unauthorized problem. It was just my guess.

It fails only a few times and almost always in my welcome (first) message.

It happened again:

Channel: Telegram
Service URL: https://telegram.botframework.com
Conversation Id: 446555179
Time: 2018-06-29 01:03:17.657 UTC−03:00

It was responding to /start with a new contact using the function SelecionaPais2. In its catch code I call SelecionaPais3 that works.

    public static async Task<string> SelecionaPais2(Activity activity)
    {
        try
        {
            // Use the data stored previously to create the required objects.
            var userAccount = new ChannelAccount(activity.From.Id, activity.From.Name);
            var botAccount = new ChannelAccount(activity.Recipient.Id, activity.Recipient.Name);

            ConnectorClient connector = ConnectorClient_Obter(activity.ServiceUrl);

            // Create a new message.
            IMessageActivity message = Activity.CreateMessageActivity();
            message.ServiceUrl = activity.ServiceUrl;
            message.ChannelId = activity.ChannelId;
            string IdConversa = "";
            if (string.IsNullOrEmpty(activity.Conversation.Id))
            {
                // Conversation ID was not stored previously, so create a conversation. 
                // Note: If the user has an existing conversation in a channel, this will likely create a new conversation window.
                IdConversa = (await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount)).Id;
            }
            else
            {
                IdConversa = activity.Conversation.Id;
            }

            SelecionaPais_Preenche_Msg(message);

            // Set the address-related properties in the message and send the message.
            message.From = botAccount;
            message.Recipient = userAccount;
            message.Conversation = new ConversationAccount(id: IdConversa);
            message.Locale = "pt-BR";
            await connector.Conversations.SendToConversationAsync((Activity)message);

            Utils.Log_Grava("sucesso em SelecionaPais2");
        }
        catch (Exception ex)
        {
            Utils.Log_Grava($"SelecionaPais2 Failed with message: {ex.Message}");

            await SelecionaPais3(activity.ChannelId,activity.ServiceUrl, activity.From.Id, activity.From.Name, activity.Recipient.Id, activity.Recipient.Name);
        }
        return ("");
    }

    public static async Task<string> SelecionaPais3(string IDCanal, string ServiceURL, string IdUsuario, string NomeUsuario, string IdBot, string NomeBot)
    {
        try
        {
            // Use the data stored previously to create the required objects.
            var userAccount = new ChannelAccount(IdUsuario, NomeUsuario);
            var botAccount = new ChannelAccount(IdBot, NomeBot);

            ConnectorClient connector = ConnectorClient_Obter(ServiceURL);

            // Create a new message.
            IMessageActivity message = Activity.CreateMessageActivity();
            message.ChannelId = IDCanal;

            message.ServiceUrl = ServiceURL;

            // Conversation ID was not stored previously, so create a conversation. 
            // Note: If the user has an existing conversation in a channel, this will likely create a new conversation window.
            string IdConversa = (await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount)).Id;

            SelecionaPais_Preenche_Msg(message);

            // Set the address-related properties in the message and send the message.
            message.From = botAccount;
            message.Recipient = userAccount;
            message.Conversation = new ConversationAccount(id: IdConversa);
            message.Locale = "pt-BR";
            await connector.Conversations.SendToConversationAsync((Activity)message);

            Utils.Log_Grava("sucesso em SelecionaPais3");
        }
        catch (Exception ex)
        {
            Utils.Log_Grava($"SelecionaPais3 Failed with message: {ex.Message}");
        }
        return ("");
    }
    public static void SelecionaPais_Preenche_Msg(IMessageActivity message)
    {
        try
        {
            message.Text = "Welcome! I am a bot that compares prices among stores!";

            message.Attachments.Add(
                new HeroCard
                {
                    Subtitle = "Please select a country:",
                    Buttons = new List<CardAction> {
                        new CardAction(ActionTypes.ImBack, $"Australia", value: $"AU", text: $"Australia", displayText: $"Australia"),
                        new CardAction(ActionTypes.ImBack, $"Brasil", value: $"BR", text: $"Brasil", displayText: $"Brasil"),
                        new CardAction(ActionTypes.ImBack, $"Canada", value: $"CA", text: $"Canada", displayText: $"Canada"),
                        new CardAction(ActionTypes.ImBack, $"Deutschland", value: $"DE", text: $"Deutschland", displayText: $"Deutschland"),
                        new CardAction(ActionTypes.ImBack, $"España", value: $"ES", text: $"España", displayText: $"España"),
                        new CardAction(ActionTypes.ImBack, $"France", value: $"FR", text: $"France", displayText: $"France"),
                        new CardAction(ActionTypes.ImBack, $"India", value: $"IN", text: $"India", displayText: $"India"),
                        new CardAction(ActionTypes.ImBack, $"Italia", value: $"IT", text: $"Italia", displayText: $"Italia"),
                        new CardAction(ActionTypes.ImBack, $"México", value: $"MX", text: $"México", displayText: $"México"),
                        new CardAction(ActionTypes.ImBack, $"Nederland", value: $"NL", text: $"Nederland", displayText: $"Nederland"),
                        new CardAction(ActionTypes.ImBack, $"United Kingdom", value: $"GB", text: $"United Kingdom", displayText: $"United Kingdom"),
                        new CardAction(ActionTypes.ImBack, $"United States", value: $"US", text: $"United States", displayText: $"United States"),
                        new CardAction(ActionTypes.ImBack, $"Россия (Russia)", value: $"RU", text: $"Россия (Russia)", displayText: $"Россия (Russia)"),
                    }
                }.ToAttachment()
            );
        }
        catch (Exception ex)
        {
            Utils.Log_Grava($"SelecionaPais_Preenche_Msg Failed with message: {ex.Message}");
        }
    }

You all may want to hold off on upgrading we will have another new version dropping soon. 3.15.3

Same error with 3.15.3. Always in proactive message that called a second later works fine. I will change my code to retry when fails.

@JonesAbramoff will you start a new issue detailing your issue. It seems yours is not related to the fix we recently put in. I would like to track it separately from this issue so we can look into it.

I am going to leave this issue open for this week to monitor any other reports.

Although frequency has decreased but the issue still exists in the updated code. Occurred 5 times in past 3 days. Only occurring after the first greeting message sent by bot.

| Conversation ID | Timestamps |
| ------------- | ------------- |
| HZCFg6owRc8FDBGlvlOpqi | 2018-06-30T10:54:04.6611466+00:00 |
| 2kbLKBZ83QPLbqr8iAF1h1 | 2018-06-30T23:13:55.0952924+00:00 |
| 1D0diPwsKoXMjvR89iqeu | 2018-07-01T13:05:13.5875871+00:00 |
| CycJsRiEzAR2NPwgu3V3v1 | 2018-07-02T18:48:07.8127725+00:00 |
| 9zvkjcwLTZaE1buVViJ58E | 2018-07-02T20:17:07.4171416+00:00 |

The exceptions occur when the bot had been idle for a long period like for 2-3 hours.

The same problem for our app.

  1. The frequency is about 1 to 2 hours of bot inactivity.
  2. We use WebChat and DirectLine channels. Both channels show the error.
  3. After 3.15.3 the error is not showing in appInsights nor on the "Health" column is the Channels tab of bot configuration page through azure portal. The "Health" column now shows "Running".
  4. We didn't have the chance to see this error happening localy on the emulator. In our case the error is on the Azure deployment,
  5. Our bot is a WebAppBot deployed on Azure
  6. After 3.15.3 app insights does not capture the error
  7. I don't have the excat timestamp as nothing is logged anymore. The error occured today around 4:30am UTC, yesterday night around 7:00pm to 8:00pm UTC. Whenever the bot is idle in general and after 1 to two hours of inactivity. I could be more specific on the times the error occures if needed.
  8. For the bot state we are using CosmosDB excactly as it is shown in the documentation.

Thanks in advance for your support
Alex

Thanks for reporting your results all, we will continue to look into this.

Looks like you are not alone here @JonesAbramoff

Hi Jason,

This problem has been around since March 15 in issue 4321 and I would like to contribute to solve it as I can. I can privately send you my source code or change it to include whatever debugging code you ask.

Right now all my messages to the user have a retry to be used when the first attempt fails.

Best regards,

Jones

Hi, experienced the same.

Bot Info
SDK Platform: C#
SDK Version: 3.12.2.4
Active Channels: Web chat, FB
Deployment Environment: On-Premise

Frequency - Happen on all the messages. Never success on sending out one.
Stack trace - There was an error sending this message to your bot: HTTP status code Unauthorized
Deployment where is this happening - On prem, local testing is fine.
State Service: Default state service

Issue Description:
Found bot no response from FB recently. Last working response received was in June 2018.
Tried to troubleshoot by testing bot in Azure web chat, the message couldnt send.
Web Chat issue logged: There was an error sending this message to your bot: HTTP status code Unauthorized.
However with the same code, the bot is functional when using emulator.

Code Example
In web.config, set microsoftappid, microsoftapppassword:

add key="MicrosoftAppId" value="0f5b4ab2-800a-4447-bfe7-c89ad9d90719"
add key="MicrosoftAppPassword" value="xxxxxxxx"

In Message controller:

public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
        if (activity.Type == ActivityTypes.Message)
        {
            var connector = new ConnectorClient(new Uri(activity.ServiceUrl));
            Activity isTypingReply = activity.CreateReply();
            isTypingReply.Type = ActivityTypes.Typing;
            await connector.Conversations.ReplyToActivityAsync(isTypingReply);

            await Conversation.SendAsync(activity, () => new Dialogs.ExceptionHandlerDialog<object>(
                new Dialogs.RootDialog()
            ));

        }
        else
        {
            HandleSystemMessage(activity);
        }
        var response = Request.CreateResponse(HttpStatusCode.OK);
        return response;
}

Reproduction Steps
https://www.facebook.com/messages/t/mayabotdemo, try talk to the bot.
Please advise if the way if the team wants to test out the azure web chat.

Expected Behavior
The bot will able to respond after received user's reply.

Actual Results
The bot does not reply now due to error logged in azure. There was an error sending this message to your bot: HTTP status code Unauthorized.

@JonesAbramoff if you think you have a fix please submit a pull request. If you do not want to submit one you can send the code to the email in my profile.

Sorry, I have no fix to suggest. I am only using a very ugly retry code to live with this failures.

@huyjack178 has provided an interesting workaround to avoid this error here: https://github.com/Microsoft/BotBuilder/issues/4322#issuecomment-405528802

@huyjack178 thank you for mentioning that post, but what if the bot is hosted as Azure web app and it is being consumed by webchat, or directline channels?
Is there any hint on how i could update the connector token?

@asfyra There is example code here: https://blog.botframework.com/2017/11/02/optimizing-latency-bot-framework/ demonstrating how to add code for periodically refreshing the token.

We upgraded to latest version of bot builder SDK (3.15.3) and we see this issue lot less frequently now.

@ujwalakhaire We are also on the latest version (3.15.3) but the issue remains. Just leave the bot inactive for a couple of hours and the error returns :cry:

This bug should have the highest priority.

We are actively looking into this.

Me Too

I meet the same problem when I use Keyvault to store my ids and keys.

I have to be tortured crazy recently.


SDK Platform: .Net

【Frequency】: After one hour I deploy, it responds nothing. Every message. No matter what I send to Bot, it responds nothing.

【Channel】: MS Teams. Web chat is ok. Or sometimes Web chat exists this problem suddenly, but it recovers quickly.

【Deployment】: Locally git to Azure

【Type of bot Functions bot】: Web App Bot. (QnA surely has this problem, LUIS maybe(I am testing))

【Is there any relevant info in app insights】: I don't know know how to see app insights about MS Teams in Azure. I get this exception just in Web chat's app insights by chance.

【Details】:
{
"message": "An error has occurred.",
"exceptionMessage": "Operation returned an invalid status code 'Unauthorized'",
"exceptionType": "Microsoft.Bot.Connector.ErrorResponseException",

"stackTrace": " at Microsoft.Bot.Connector.Conversations.d__9.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

This is happening for my bot as well, details:

1) Frequency - Roughly once every 24 hours, usually between 10:00 and 10:30 UTC (which, as others have commented, is usually after a longer period of inactivity for our bot)
2) Channel - Direct Line. We're only on this channel so I can't speak to other ones.
3) Stack trace:

Operation returned an invalid status code 'Unauthorized'
**************************************************
StatusCode=401
ReasonPhrase=Unauthorized
Request=Microsoft.Rest.HttpRequestMessageWrapper
Response=Microsoft.Rest.HttpResponseMessageWrapper
TargetSite=Void MoveNext()
Source=Microsoft.Bot.Connector
HResult=-2146233088
StackTrace
**************************************************
   at Microsoft.Bot.Connector.Conversations.<SendToConversationWithHttpMessagesAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Connector.ConversationsExtensions.<SendToConversationAsync>d__5.MoveNext()

4) Deployment - Customized container orchestration service (hosted in Azure East US 2)
5) Bot type - Self hosted
6) No relevant info in App Insights. One or two requests fail to authorize, and all subsequent requests succeed for approximately the next 24 hours.
7) Some conversation ID (directline) / timestamp (UTC) pairs:

Rt7tQfIk8e6wPhDyWYPzr / 2018-07-30 10:15:24.4937
18XZnA6tIWb435j6DxkJRZ / 2018-07-28 10:27:01.8811
HkJ3HIQZMP87rN6BZM9pXL / 2018-07-27 13:34:12.1247
AgrLyhLJUPtEHJ7za2haPQ / 2018-07-26 10:09:22.2380
kUkM3l6ihH5MX0Jn5ziy / 2018-07-25 10:01:47.4448

8) We use the DocumentDbBotDataStore implementation of IBotDataStore for state storage in CosmosDB.

Hi,
I'm facing this issue to. It happens randomly like once a day after longer bot inactivity. I updated to latest version of bot builder SDK (3.15.3)

Hi,
I'm facing this issue to. I updated to latest version of bot builder SDK (3.15.3):

Sunday, August 05, 2018

MessagesController, Post

Medium

Error

Error

Microsoft.Bot.Connector

Operation returned an invalid status code 'MethodNotAllowed'

MoveNext

Microsoft.Rest.HttpOperationException

e-career-temp

10.103.201.50

at Microsoft.Bot.Connector.BotState.d__8.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Connector.BotStateExtensions.d__7.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.ConnectorStore.-LoadAsync>d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.CachingBotDataStore.d__8.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.CachingBotDataStore.-LoadAsync>d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.BotDataBase1.<LoadData>d__16.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.BotDataBase1.d__8.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.DialogTaskManagerBotDataLoader.d__11.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.ExceptionTranslationDialogTask.d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.SerializeByConversation.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUser.d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUser.d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.LogPostToBot.d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Conversation.d__11.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Conversation.d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at RechChatBotAppBot.MessagesController.d__9.MoveNext() in E:\New folder (11)\RechChatBotAppBot\RechChatBotAppBot\Controllers\MessagesController.cs:line 126

I am experiencing the problem with :
Microsoft.Bot.Schema.BotTimeoutException: POST to MyMangosteenBotReg timed out after 15s
at Microsoft.Bot.ChannelConnector.BotAPI+d__30.MoveNext (Microsoft.Bot.ChannelConnector, Version=3.2.2.2, Culture=neutral, PublicKeyToken=null)

I am using the latest Bot.builder SDK 3.15.3

It happens periodically and it seems to happen after a user is inactive but it happens at different time periods. Other users can be using the bot and not experience the issue.

In order to clear it, I have to stop and restart the app.

I am using the Facebook Channel exclusively other than testing.

I am in a pickle here because I assured my bosses that it was a good thing to build on top of the Microsoft infrastructure. We are trying to launch a new product using the bot this week. Please help.

Hi,
I'm using bot within following scenario:

  • webchat sends initConversation event at the beginning of a conversation
  • bot replies on it with welcome message.

When bot is idle e.g. for a couple of hours I sometimes get Unauthorized exception when bot is trying to reply.

I'm tried following workaround which seems that fixes the issue:

  • call GetTokenAsync() on MicrosoftAppCredentials of your bot just before reply
    ```c#
    if (string.Equals("initConversationEvent", message.Name, StringComparison.OrdinalIgnoreCase))
    {
    // possible workaround to avoid occasional 401 http errors when replying back to user, see https://github.com/Microsoft/BotBuilder/issues/4733
    await _botRegistrationAppCredentials.GetTokenAsync();
await ReplyWithWelcomeMessageAsync(message);

}
```

I have some good news, we have a release that should address this issue coming out soon. If you would like to test it you can try the build on our MyGet daily build feed

@aymandaqa your problem seems to be unrelated, can you please open a new issue and share the code from your messages controller.

I had the same issues mentioned in this thread. The bot wouldn't work when authentication is turned on and gave me 401 errors. Now I have upgraded to the new 3.16 bot builder update and I get following compile time errors
CS1705 Assembly 'Microsoft.Bot.Builder' with identity 'Microsoft.Bot.Builder, Version=3.16.0.37658, Culture=neutral, PublicKeyToken=xxxx' uses 'Microsoft.Bot.Connector, Version=3.16.0.37658, Culture=neutral, PublicKeyToken=xxxx' which has a higher version than referenced assembly 'Microsoft.Bot.Connector' with identity 'Microsoft.Bot.Connector, Version=3.15.3.0, Culture=neutral, PublicKeyToken=yyy' VendorDetailsBotApplicationWithLUIS

What gives?

@ani-sm somehow the versions got out of sync. if you upgrade your packages using these commands for bot.builder and bot.connector the packages should install correctly. I just tested it and was able to successfully build. Basically the solution is to install the 3.16.0.37621 versions of both. We will get this sorted out moving forward.

Microsoft.Bot.Builder:

Install-Package Microsoft.Bot.Builder -Version 3.16.0.37621 -Source https://botbuilder.myget.org/F/botbuilder-v3-dotnet-daily/api/v3/index.json

Microsoft.Bot.Connector:

Install-Package Microsoft.Bot.Connector -Version 3.16.0.37621 -Source https://botbuilder.myget.org/F/botbuilder-v3-dotnet-daily/api/v3/index.json

A couple updates...
@JasonSowers Thanks.. that helped... I did get some compile errors but now I able to test the bot in the emulator with authentication turned on. I have deployed it to Azure and with all settings in place I'm getting "Sorry, my bot code is having an issue." errors. When I debugg it with ngrok I see some messages due to using default state.
Since using default state is not allowed in production, could this be the case for the error above? Or can it be still related to the Bot authentication ?

Diving Deep...will provide more updates when I surface!

It's hard to say without seeing your code @ani-sm. "Sorry, my bot code is having an issue." is a catch-all error that doesn't provide much information. A stack trace or some code where the error is occurring may help to diagnose.

I'm suffering from this issue too, every time I update the packages recently a new issues seems to come up that only becomes apparent when the app is subjected to large amounts of use in production when it's too late. I'd only recently upgraded to avoid the issue many others were suffering whereby the bot would forget it's state (https://github.com/Microsoft/BotBuilder/issues/4477). Really disappointing.

Happens in production using a Web App Bot and Azure.

Here is the stack trace:
ErrorResponseException: Operation returned an invalid status code 'Unauthorized' Module "Microsoft.Bot.Connector.Conversations", line 1430, col 0, in ReplyToActivityWithHttpMessagesAsync Void MoveNext() Module "System.Runtime.CompilerServices.TaskAwaiter", line 26, col 0, in ThrowForNonSuccess Void ThrowForNonSuccess(System.Threading.Tasks.Task) Module "System.Runtime.CompilerServices.TaskAwaiter", line 40, col 0, in HandleNonSuccessAndDebuggerNotification Void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) Module "Microsoft.Bot.Connector.ConversationsExtensions", line 211, col 0, in ReplyToActivityAsync Void MoveNext() Module "System.Runtime.CompilerServices.TaskAwaiter", line 26, col 0, in ThrowForNonSuccess Void ThrowForNonSuccess(System.Threading.Tasks.Task) Module "System.Runtime.CompilerServices.TaskAwaiter", line 40, col 0, in HandleNonSuccessAndDebuggerNotification Void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) Module "Microsoft.Bot.Builder.Dialogs.Internals.AlwaysSendDirect_BotToUser+<Microsoft-Bot-Builder-Dialogs-Internals-IBotToUser-PostAsync>d__4", line 125, col 0, in MoveNext Void MoveNext() Module "System.Runtime.CompilerServices.TaskAwaiter", line 26, col 0, in ThrowForNonSuccess Void ThrowForNonSuccess(System.Threading.Tasks.Task) Module "System.Runtime.CompilerServices.TaskAwaiter", line 40, col 0, in HandleNonSuccessAndDebuggerNotification Void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) Module "Microsoft.Bot.Builder.Dialogs.Internals.InputHintQueue+<Microsoft-Bot-Builder-Dialogs-Internals-IMessageQueue-QueueMessageAsync>d__4", line 308, col 0, in MoveNext Void MoveNext()

We are also facing the same issue:

Frequency - randomly after 1 or 2 hrs (Users in PROD are getting frustrated with this issue)
What channels is this happening on, is it working on any channels? - Web Chat
Stack trace

[{"parsedStack":[{"assembly":"Microsoft.Bot.Connector, Version=3.15.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"Microsoft.Bot.Connector.Conversations+d__7.MoveNext","level":0,"line":0},{"assembly":"mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089","method":"System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess","level":1,"line":0},{"assembly":"mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089","method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","level":2,"line":0},{"assembly":"Microsoft.Bot.Connector, Version=3.15.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"Microsoft.Bot.Connector.ConversationsExtensions+d__5.MoveNext","level":3,"line":0},{"assembly":"mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089","method":"System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess","level":4,"line":0},{"assembly":"mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089","method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","level":5,"line":0},{"assembly":"mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089","method":"System.Runtime.CompilerServices.TaskAwaiter`1.GetResult","level":6,"line":0},{"assembly":"SupportBot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","method":"SupportBot.MessagesController+<>c__DisplayClass1_0+<b__0>d.MoveNext","level":7,"line":138,"fileName":"\SupportBot\Controllers\MessagesController.cs"}],"outerId":"0","message":"Operation returned an invalid status code 'Unauthorized'","type":"Microsoft.Bot.Connector.ErrorResponseException","id":"42471124"}]

Deployment where is this happening - Local testing? Azure? Both? -- Azure

I got around this issue by moving from the table interface and moving to the SQL (DocumentDB) interface. Why that cleared up the problem I don't know, but the majority of the people having problems were using the table interface it seemed to me.

Thank you for opening an issue against the Bot Framework SDK v3. As part of the Bot Framework v4 release, we’ve moved all v3 work to a new repo located at https://github.com/microsoft/botbuilder-v3. We will continue to support and offer maintenance updates to v3 via this new repo.

From now on, https://github.com/microsoft/botbuilder repo will be used as hub, with pointers to all the different SDK languages, tools and samples repos.

As part of this restructuring, we are closing all tickets in this repo.

For defects or feature requests, please create a new issue in the new Bot Framework v3 repo found here:
https://github.com/microsoft/botbuilder-v3/issues

For Azure Bot Service Channel specific defects or feature requests (e.g. Facebook, Twilio, Teams, Slack, etc.), please create a new issue in the new Bot Framework Channel repo found here:
https://github.com/microsoft/botframework-services/issues

For product behavior, how-to, or general understanding questions, please use Stackoverflow.
https://stackoverflow.com/search?q=bot+framework

Thank you.

The Bot Framework Team

Hi,

@JasonSowers @EricDahlvang
We are still facing the issue in 3.15.2.2

  • Frequency - How often is this happening? Every message? Randomly and how often ex. 1 out of 10 messages => Daily 1 time for the first user
  • What channels is this happening on, is it working on any channels? => Webchat
  • Stack trace =>

directline.botframework.com | HTTP | POST /v3/conversations/(ID goes here)/activities/(ID goes here) | https://directline.botframework.com/v3/conversations/(ID goes here)/activities/(ID goes here) | FALSE | 401 | 434 | 250ms-500ms

  • Deployment where is this happening - Local testing? Azure? Both? Azure Hosting

@alokraj68 This issue was fixed with 3.19.n Please upgrade to the latest Bot Builder V3 version: https://www.nuget.org/packages/Microsoft.Bot.Builder/3.20.1

@EricDahlvang
We did updated to 3.20.1 and deployed but yet to test for few days to confirm.

Thanks for quick reply.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

peterbozso picture peterbozso  ·  3Comments

akakoychenko picture akakoychenko  ·  3Comments

maba4891 picture maba4891  ·  3Comments

mattlanham picture mattlanham  ·  3Comments

hailiang-wang picture hailiang-wang  ·  3Comments