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

Getting issue while enabling direct line app service extension in azure bot service with VA template bot

Open VidhyaSanjeevi opened this issue 5 years ago • 19 comments

What project is affected?

Virtual Assistant

What language is this in?

C#

What happens?

Getting issue while enabling direct line app service extension in azure bot service with VA template bot

What are the steps to reproduce this issue?

I have followed the exact steps mentioned in below Microsoft link:

https://docs.microsoft.com/en-us/azure/bot-service/bot-service-channel-directline-extension-net-bot?view=azure-bot-service-4.0

Still the value of ib and ob are coming false: {"v":"1.0.0.0.55fa54091a1e3b168628d4000ee2b06a88bbc2ac","k":true,"ib":false,"ob":false,"initialized":true}

Bot in webchat stops working after adding OutOfProcess setting in .csproj file. webchaterror

Also am not able to generate token from the below link: https://[my bot name here].azurewebsites.net/.bot/v3/directline/tokens/generate

I had replicate the same config on two bots but no luck. Please help me on this its urgent. I have attached my changes, please let me know where i'm getting wrong or is this the issue with Microsoft.

apllication settings

ib and on values

namedpipe

outofprocess

web socket config

What were you expecting to happen?

bot should connect with bot channel registration.

Can you share any logs, error output, etc.?

I have tried debugging it & error is coming in UseNamedPipes middleware and found below exception:

I am using latest virtual assistant template: https://github.com/microsoft/botframework-solutions/tree/master/samples/csharp/assistants/virtual-assistant

image

image

Stack Trace at Microsoft.Bot.Builder.Integration.AspNet.Core.ApplicationBuilderExtensions.UseNamedPipes(IApplicationBuilder applicationBuilder, String pipeName) at VirtualAssistantSample.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in C:\Users\Taruna.Soni\Desktop\virtual-assistant\VirtualAssistantSample\Startup.cs:line 171 at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder) at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.b__0(IApplicationBuilder builder) at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.b__2(IApplicationBuilder app) at Microsoft.ApplicationInsights.AspNetCore.ApplicationInsightsStartupFilter.<>c__DisplayClass2_0.b__0(IApplicationBuilder app) at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.g__MiddlewareFilterBuilder|0(IApplicationBuilder builder) at Microsoft.AspNetCore.Server.IISIntegration.IISSetupFilter.<>c__DisplayClass4_0.b__0(IApplicationBuilder app) at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.b__0(IApplicationBuilder app) at Microsoft.AspNetCore.Hosting.GenericWebHostService.d__31.MoveNext()

Any screenshots or additional context?

alt text alt text

Above issue raised also here : https://github.com/MicrosoftDocs/bot-docs/issues/1965

VidhyaSanjeevi avatar Mar 25 '21 15:03 VidhyaSanjeevi

I will suggest we update to the latest SDK and try again..

xieofxie avatar Mar 25 '21 23:03 xieofxie

@xieofxie Using latest GA version only. Microsoft.Bot.Solutions Version 1.0.1 Botframework version 4.9.3 Virtual Assistant generated from visual studio extension version 4.9.1.2

VidhyaSanjeevi avatar Mar 28 '21 13:03 VidhyaSanjeevi

@SSanjeevi we are working on a major release, so apologies for the delay in getting to this issue. We will respond back with a resolution as soon as we can.

msomanathan avatar Mar 30 '21 18:03 msomanathan

@SSanjeevi Edit Startup.cs class and update the below line in ConfigureServices Method. services.AddSingleton<BotFrameworkHttpAdapter, DefaultAdapter>(); to services.AddSingleton<IBotFrameworkHttpAdapter, DefaultAdapter>();

Cheers. Thanks me later.

gourav-madan avatar Apr 02 '21 06:04 gourav-madan

Hi @SSanjeevi,

@gourav-madan has the right of it - thank you for the assistance! Please attempt the following adjustment above and let us know if this helps resolve your issue. If not, we can investigate further.

peterinnesmsft avatar Apr 05 '21 17:04 peterinnesmsft

@gourav-madan i updated as per your suggestion even the build solution failed then - i fixed it by updating the below in BotController:

BotFrameworkHttpAdapter to IBotFrameworkHttpAdapter

then code able to build and then i deployed to app service and then followed this document: https://docs.microsoft.com/en-us/azure/bot-service/bot-service-channel-directline-extension-net-bot?view=azure-bot-service-4.0

and https://docs.microsoft.com/en-us/azure/bot-service/bot-service-channel-directline-extension-webchat-client?view=azure-bot-service-4.0

after that got the below correct values. image

but when connecting from bot webchat got the token generated but got error saying websocket connection failed error in browser console.

then in log of app service got the below error:

2021-04-06 11:00:40.948 +00:00 [Error] Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: An unhandled exception has occurred while executing the request.System.InvalidOperationException: StatusCode cannot be set because the response has already started.at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ThrowResponseAlreadyStartedException(String value)at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.set_StatusCode(Int32 value)at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.Microsoft.AspNetCore.Http.Features.IHttpResponseFeature.set_StatusCode(Int32 value)at Microsoft.AspNetCore.Http.Internal.DefaultHttpResponse.set_StatusCode(Int32 value)at Microsoft.AspNetCore.Mvc.StatusCodeResult.ExecuteResult(ActionContext context)at Microsoft.AspNetCore.Mvc.ActionResult.ExecuteResultAsync(ActionContext context)at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result)at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsync[TFilter,TFilterAsync]()at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultFilters()at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)at Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext context)at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.InvokeCore(HttpContext context)at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) 2021-04-06 11:00:40.955 +00:00 [Error] Microsoft.AspNetCore.Server.Kestrel: Connection id "0HM7OT1NVBJ5M", Request id "0HM7OT1NVBJ5M:00000001": An unhandled exception was thrown by the application.System.InvalidOperationException: StatusCode cannot be set because the response has already started.at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ThrowResponseAlreadyStartedException(String value)at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.set_StatusCode(Int32 value)at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.Microsoft.AspNetCore.Http.Features.IHttpResponseFeature.set_StatusCode(Int32 value)at Microsoft.AspNetCore.Http.Internal.DefaultHttpResponse.set_StatusCode(Int32 value)at Microsoft.AspNetCore.Mvc.StatusCodeResult.ExecuteResult(ActionContext context)at Microsoft.AspNetCore.Mvc.ActionResult.ExecuteResultAsync(ActionContext context)at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result)at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsync[TFilter,TFilterAsync]()at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultFilters()at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)at Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext context)at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.InvokeCore(HttpContext context)at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.Invoke(HttpContext httpContext)at Microsoft.AspNetCore.Builder.Extensions.UsePathBaseMiddleware.Invoke(HttpContext context)at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication1 application)

`

Further checking the VA template code we see implementation of default adapter with HTTP adapter with BotFrameworkHttpAdapter -doubt whether this is causing any issue and another thing in start up file: services.AddSingleton<BotAdapter>(sp => sp.GetService<BotFrameworkHttpAdapter>());

VidhyaSanjeevi avatar Apr 06 '21 11:04 VidhyaSanjeevi

HI @SSanjeevi, I'll spend some time investigating this today and get back to you shortly.

peterinnesmsft avatar Apr 09 '21 16:04 peterinnesmsft

@Batta32 - could you take a look at this follow up issue and see if there is any suggestions for how this scenario can be enabled? Thanks!

lauren-mills avatar Apr 13 '21 18:04 lauren-mills

Sure @lauren-mills, we will start working on this issue asap! We will back as soon as we have any updates.

Batta32 avatar Apr 13 '21 18:04 Batta32

Hi @SSanjeevi, we were able to reproduce part of the issue you are describing, specifically the correct ib and ob values.

However, we are following this document to integrate WebChat, but we are not being able to generate the token as you said.

We will let you know as soon as we have an update.

The values of in and ob after setting OutOfProcess in .csproj image

The error when running the WebChat client image

VictorGrycuk avatar Apr 16 '21 16:04 VictorGrycuk

Hi @SSanjeevi, we successfully obtained the token using the web chat, and we got the web socket connection failed error that you mentioned. However, we were not able to find the App Services log that you shared.

We noticed that enabling the Web Socket option in the App Service resource, the web socket connection failed error is fixed, but the following error appears: Failed to connect Error: Connection response code 500 .

In order to narrow the issue, we came up with some questions:

  1. Where do you find the App Service logs?
  2. Which Web Chat are you using?
  3. Have you enabled the Web Socket option in your App Service resources as this document suggest?
  4. Are you able to talk with the bot through the Emulator or the embedded web chat in the web app bot resource?

These were our repro steps:

  1. Create Virtual Assistant using the Template
  2. Deploy Virtual Assistant using deploy.ps1
  3. Configure DL App Service Extension with named pipes following the attached document Configure .NET bot for extension
  4. Apply this change
  5. Configure the bot to run OutOfProcess, as it's described here
  6. Publish the virtual assistant using publish.ps1
  7. Cloned the repo BotFramework-WebChat
  8. Use Web chat with DL App Service extension following the attached document Use Web Chat with the direct line app service extension
  9. Run sample 01.getting-started
  10. See token correctly generated in the web console
  11. If you don't have enabled the web socket option in App Services resources you will see the web socket connection failed error, but if you have it enabled you will see the failed to connect error: connection response code 500

We will continue reviewing this issue, and as soon as we have any update we will back to you 😊 .

Web socket connection failed error with the expected token image

VictorGrycuk avatar Apr 16 '21 20:04 VictorGrycuk

Hi @VictorGrycuk,

I also able to generate token after enabling web socket connection but getting 500 error as you mentioned. After getting the 500 error I seen the logs in app service it shown that log trace I shared.

I have wrote some code to log the exceptions in startup class that log shown that error logs. I have been seeing the logs in log stream in app service.

I haven't tested with emulator, will check and let you know.

VidhyaSanjeevi avatar Apr 17 '21 02:04 VidhyaSanjeevi

@SSanjeevi could you please share program.cs file code? I think code is breaking in this class only.

gourav-madan avatar Apr 17 '21 05:04 gourav-madan

Hi @SSanjeevi we successfully communicated with the bot through the Web Chat, enabling DL ASE.

As we noticed that there is a timeout period in the App Service, we configured the "Always On" option in the App Service general settings in on. By doing this we prevent the Failed to connect Error: Connection response code 500 and the manual reactivation of the App Service.

We put together all the required changes in Virtual Assistant in this commit. Here you can see:

  • The required changes in the Startup and BotController classes
  • The configuration of OutOfProcess option, in the .csproj file.

We followed these steps:

  1. Apply the changes above
  2. Follow the instructions of the documentation Configure .NET bot for extension
  3. Follow the instructions of the documentation Use Web Chat with the direct line app service extension
  4. Follow these instructions to run the index.html and run the Web Chat

Virtual Assistant responding in Web Chat with token image

Always on option image

Let us know if this helps 😊 .

VictorGrycuk avatar Apr 19 '21 20:04 VictorGrycuk

Closing due to inactivity, reopen if needed

Batta32 avatar May 03 '21 18:05 Batta32

@Batta32 - can we check this issue now?

I followed your steps and now am able to generate token for the app service bot with directline extension setup - but still getting 500 error in response of websocket connection.

image image

VidhyaSanjeevi avatar May 18 '21 12:05 VidhyaSanjeevi

its working fine thanks for the guidance.

VidhyaSanjeevi avatar May 18 '21 13:05 VidhyaSanjeevi

its working fine thanks for the guidance.

Hello @SSanjeevi , I am also facing similar issue, i am using VA template and enabled DL ASE , Whenever i am trying to access client side bot (Which is getting token properly) but failing to communicate with bot service giving error as:

webchat.js:2 WebSocket connection to 'wss://xxx.net/.bot/v3/directline/conversations/connect?token=ew0KICAiYWxnIjogIlJTMjU2IiwNCiAgImtpZCI6ICJ2cG4y... failed:

image

Could you please suggest changes that helped you to resolve this issue ? I have raised issue here : https://github.com/microsoft/botframework-solutions/issues/3849 as even after following all the steps i could not see it working.

pravinambekar avatar Jan 12 '22 11:01 pravinambekar

Here is my code i used: https://github.com/SSanjeevi/VirtualAssistantDirectlineExtn

VidhyaSanjeevi avatar Jan 23 '22 15:01 VidhyaSanjeevi