Search code examples
c#botframeworkazure-bot-service

MS Bot Framework V3 web chat/direct line issue - Internal Server Error 500


I am new to C# and the Bot Framework (V3) and have been asked to begin testing an existing bot on a project I have joined. The bot itself works fine on the Bot Emulator and when hosted on Skype, but for some reason the web chat on Azure does not work. As the web chat uses the Direct Line, it kind of puts a halt to running tests for now. I have spent a lot of time scouring the V3 Github page and here on SO but I've not been able to find a solution.

The conversation seems to initiate OK to begin, as the Bot sends the user a message but all user responses don't get sent and the Bot responds with the error message 'Sorry, my bot code is having an issue'. See -

Bot error message

Azure lists it as a 500 error - internal server error. see

Error messages in Azure

Error messages in Azure

I then looked at the messages in the Chrome Dev Tools tab and get the same error as well as a 502 error and, more recently (or I never noticed it before), a CORS error as well. See

Chrome Dev Tools console

Chrome Dev Tools console

After this I used Application Insights on Azure and for each instance when I tried to use the Web Chat there would be three items;

  • A customEvent (StatusCode: 200), presumably for the message the Bot sends at the beginning of the conversation.
  • An exception with a problemId "System.Exception at Microsoft.Bot.ChannelConnector.BotAPI+d__31.MoveNext"
  • Another customEvent (StatusCode : 500)

As I'm not very familiar with the whole set-up between C# and the Bot Framework I'm not really sure where the issue lies. Here's some screenshot of what the exception message looks like -

Messages of single operationId

Messages for single operationId

Exception details (1)

Exception details (1)

Exception details (2)

Exception details (2)

Exception details (3)

Exception details (3)

Exception details (4)

Exception details (4)

I had some thoughts on these messages:

  1. The 'Outer assembly' is described as 'Microsoft.Bot.ChannelConnector, Version=3.2.2.5, Culture=neutral, PublicKeyToken=null' - does the lack of a PublicKeyToken mean that the user isn't getting assigned a token because of the error? Or should this be happening first and the error occurring because the user has no token?
  2. The stack trace is pointing at a line in one of the dialog files but from looking at the code, I can't really see what the issue is? I actually removed the section that was being flagged but it simply changed the line in the code where the issue was to the preceding section so I'm not really sure that there is an issue with this file at all?

If anyone has any thoughts on this and what the cause of the issue might be I would really appreciate it.

Additionally, here's two things I've tried to do to fix this that haven't made any difference;

  • Ensured that when publishing the profile to Azure to tick the box to 'Delete all
  • Made sure all packages were up to date (including installing the bot.connector.directline package, which wasn't already there for some reason)

Solution

  • So the resolution to my problem was as per Steven Kanberg's suggestions in the comments above. While our state management had been using the deprecated version (which is now updated), it was a CORS issue caused by the bots being in different deployment slots to the app services. Once the URIs of the app services were added as Trusted Origins the problem was solved. Thanks to Steven Kanberg for all the help.