botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

500 Internal Server Error in emulator - V3

Open Huskitch opened this issue 10 years ago • 54 comments

I've recently upgraded my bot to the new V3 bot framework, and since then I've been getting 500 InternalServerErrors in the emulator and the "sorry, the bot is having trouble responding" messages in Slack, breakpoints anywhere in the method below don't get triggered at all so I can't really get a stack trace.

        public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
        {
            if (activity.Type == ActivityTypes.Message)
            {
                ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));

                // return our reply to the user
                Activity reply = activity.CreateReply("hello world");
                await connector.Conversations.ReplyToActivityAsync(reply);
            }
            else
            {
                HandleSystemMessage(activity);
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);
            return response;
        }

This code is the default VS template code, with the correct Web.config settings.

Below is what appears in the log when testing the connection to the bot:

InternalServerError
{
  "message": "An error has occurred.",
  "exceptionMessage": "Could not load type 'System.IdentityModel.Tokens.TokenValidationParameters' from assembly 'System.IdentityModel.Tokens.Jwt, Version=5.0.0.127, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.",
  "exceptionType": "System.TypeLoadException",
  "stackTrace": "   at Microsoft.Bot.Connector.BotAuthentication.<OnAuthorizationAsync>d__16.MoveNext()\r\n   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)\r\n   at Microsoft.Bot.Connector.BotAuthentication.OnAuthorizationAsync(HttpActionContext actionContext, CancellationToken cancellationToken)\r\n   at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.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 System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}

Huskitch avatar Jul 12 '16 07:07 Huskitch

Hi,

I had another problem: the NewtonSoft assembly was at version 9.x . Fixed that, redeployed, and now it seems to be working, error 500 is gone. I still have a compilation warning:

1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.

... but whatever this is, the bot seems to be working now.

(and I did remove the redirect from web.config)

lokijota avatar Jul 16 '16 00:07 lokijota

I can confirm that if you accidentally upgrade your nugget packages, you will have to downgrade the packages and update the dependencies in the web.config file. I used TheMakerBotShow example to compare my project and everything worked find after updating.

michael-watson avatar Jul 26 '16 17:07 michael-watson

Looking at the most recent reports on this thread, the latest outstanding issues related to assembly bindings. Are there any open runtime issues still present in your code?

dandriscoll avatar Aug 03 '16 23:08 dandriscoll

I am closing this issue assuming that the improvements in auth reliability and exception translation released in nuget 3.1 addresses all of the issues in this thread.

msft-shahins avatar Aug 05 '16 01:08 msft-shahins

Hello All,

I am facing the same issue like 500 internal server error. I changed the code to version 3. Please help me out

nitk-rashid avatar Aug 09 '16 20:08 nitk-rashid

@nitk-rashid attach a debugger to your bot and see what exception is getting thrown by the bot when it receives the message.

msft-shahins avatar Aug 09 '16 21:08 msft-shahins

One weird trick to get your bot to work in development: Run it with the debugger attached. It seems the BotAuthentication filter attribute will return early if MicrosoftAppId is empty, but only when debugger is attached. See line 27.

https://docs.botframework.com/en-us/csharp/builder/sdkreference/d0/d3b/_bot_authentication_8cs_source.html

JonathanNagy avatar Sep 30 '16 18:09 JonathanNagy

I'm getting this now, and unable to hit a breakpoint. Are these dependencies still needing to be from versions earlier this year?

StingyJack avatar Nov 14 '16 12:11 StingyJack

Maybe it's about changing the scope of your methods in the messagescontroller from "public" to "private".

garellanob avatar Mar 07 '17 18:03 garellanob

This framework was too unstable and the docs not clear enough so I stopped using it. (That and the requirement to publish it - not OK for on premise connectivity)

StingyJack avatar Mar 07 '17 18:03 StingyJack

i create my bot using bot builder framework in asp.net .Bot work fine in emulator but give me error when i try to connect it with skype ...

"Your bot did not respond to our Ping request with a success code. Please verify your bot is running and responsive before Publishing your bot. The error received from your bot was: Unauthorized(401), BotAuthenticator failed to authenticate incoming request!"

please help me !!

UsamaAslam avatar Jun 19 '17 09:06 UsamaAslam

@UsamaAslam - You should check existing open and closed issues for "401" errors (there are many that have been closed) or open a new issue for that. This thread is for 500 errors.

StingyJack avatar Jun 19 '17 10:06 StingyJack

@stingyJack - sorry to disturb you but i already open new thread and i receive no response so that is why i post here . if you know any thing please inform me i will be very thankful to you

UsamaAslam avatar Jun 19 '17 10:06 UsamaAslam

@usamaalam - If none of the existing closed "401" issues matched your problem (not likely - a similar error message present is in several), you will just have to wait for the maintainer of this module to reply back.

StingyJack avatar Jun 19 '17 10:06 StingyJack