question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"The CancellationTokenSource has been disposed" error in Teams when using Microsoft.Bot.Components.Recognizers.CustomQuestionAnsweringRecognizer

See original GitHub issue

I am using Microsoft.Bot.Components.Recognizers.CustomQuestionAnsweringRecognizer for enabling my CQA resource in my Bot built-in Bot Composer. When I publish a new version of the bot to Azure Bot Service, my bot stops answering and I get the error “The CancellationTokenSource has been disposed”. I have debugged and found out that it is indeed when CQA dialog that is causing this problem. Here is the entire error code:

Exception: System.ObjectDisposedException: The CancellationTokenSource has been disposed.    at System.Threading.CancellationTokenSource.ThrowObjectDisposedException()    at System.Threading.CancellationTokenSource.Cancel()    at Microsoft.Bot.Builder.ShowTypingMiddleware.FinishTypingTaskAsync(ITurnContext turnContext)    at Microsoft.Bot.Builder.ShowTypingMiddleware.<OnTurnAsync>b__4_0(ITurnContext ctx, List1 activities, Func1 nextSend)    at Microsoft.Bot.Builder.TelemetryLoggerMiddleware.<>c__DisplayClass7_0.<<OnTurnAsync>b__0>d.MoveNext() — End of stack trace from previous location where exception was thrown —    at Microsoft.Bot.Builder.TurnContext.SendActivityAsync(IActivity activity, CancellationToken cancellationToken)    at Microsoft.Bot.Builder.TurnContext.SendActivityAsync(String textReplyToSend, String speak, String inputHint, CancellationToken cancellationToken)    at Microsoft.Bot.Builder.Dialogs.Adaptive.Runtime.CoreBotAdapter.<.ctor>b__0_0(ITurnContext turnContext, Exception exception)    at Microsoft.Bot.Builder.BotAdapter.RunPipelineAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken)    at Microsoft.Bot.Builder.CloudAdapterBase.ProcessActivityAsync(AuthenticateRequestResult authenticateRequestResult, Activity activity, BotCallbackHandler callback, CancellationToken cancellationToken)    at Microsoft.Bot.Builder.CloudAdapterBase.ProcessActivityAsync(String authHeader, Activity activity, BotCallbackHandler callback, CancellationToken cancellationToken)    at Microsoft.Bot.Builder.Integration.AspNet.Core.CloudAdapter.ProcessAsync(HttpRequest httpRequest, HttpResponse httpResponse, IBot bot, CancellationToken cancellationToken)    at Bot.Controllers.BotController.PostAsync(String route) in /Users/danielhjelm/Desktop/ChatBot/Bot/Bot/Controllers/BotController.cs:line 67    at lambda_method(Closure , Object )    at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()    at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)    at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Logged|12_1(ControllerActionInvoker invoker)    at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)    at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)    at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)    at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)    at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)    at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)    at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)    at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)    at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.Invoke(HttpContext httpContext)    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

Issue Analytics

  • State:open
  • Created 6 months ago
  • Comments:15

github_iconTop GitHub Comments

1reaction
ramfattahcommented, Apr 26, 2023

Thanks for the update and detail explanation @DanielHjelm.

Initially, I tested with QnA Intent Recognizer inside the root dialog. I can try to use the ConversationUpdate Activity to start a QA dialog to see if it reproduces the same behavior.

Will report back soon.

0reactions
DanielHjelmcommented, May 30, 2023

@ramfattah Any other suggestions on how to do this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · microsoft/botframework-components
"The CancellationTokenSource has been disposed" error in Teams when using Microsoft.Bot.Components.Recognizers.
Read more >
The CancellationTokenSource has been disposed ...
It seems like your using client = new HttpClient... 's CancellationToken has already been consumed on the first client.GetStringAsync() call.
Read more >
Azure Bot Service - Microsoft Q&A
Bot Framework Authentication Error. I am trying to develop a chat bot for teams that uses the graph API to change the out...
Read more >
How to: Listen for Multiple Cancellation Requests | ...
This example shows how to listen to two cancellation tokens simultaneously so that you can cancel an operation if either token requests it....
Read more >
Azure Bot Service - Microsoft Q&A
I found this custom component (Microsoft.Bot.Components.Recognizers.CustomQuestionAnsweringRecognizer) that will allow me to easily integrate my bot (via bot ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found