VA Sample (Potentially calendar skill sample)
C#
In Teams, when two skills which require authentication are linked to VA, a System.ArgumentException
is observed after successful login (SSO enabled).
VA setup with skill requiring authentication linked and installed in Teams.
Skill dialog continues.
System.ArgumentException: An item with the same key has already been added. Key: BotFrameworkAdapter.InvokeResponse
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at Microsoft.Bot.Builder.TurnContextStateCollection.Add[T](String key, T value)
at Microsoft.Bot.Builder.BotFrameworkAdapter.SendActivitiesAsync(ITurnContext turnContext, Activity[] activities, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.TurnContext.<>c__DisplayClass25_0.<<SendActivitiesAsync>g__SendActivitiesThroughAdapter|1>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at SampleVA.Dialogs.MainDialog.StoreOutgoingActivitiesAsync(ITurnContext turnContext, List`1 activities, Func`1 next) in D:\a\r1\a\_eva\build-artifact\eva\Dialogs\MainDialog.cs:line 462
at Microsoft.Bot.Solutions.Middleware.SetSpeakMiddleware.<>c.<<OnTurnAsync>b__8_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Bot.Builder.TranscriptLoggerMiddleware.<>c__DisplayClass3_0.<<OnTurnAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
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.Dialogs.SkillDialog.SendToSkillAsync(ITurnContext context, Activity activity, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.Dialogs.SkillDialog.ContinueDialogAsync(DialogContext dc, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.Dialogs.DialogContext.ContinueDialogAsync(CancellationToken cancellationToken)
at SampleVA.Dialogs.MainDialog.OnContinueDialogAsync(DialogContext innerDc, CancellationToken cancellationToken) in D:\a\r1\a\_eva\build-artifact\eva\Dialogs\MainDialog.cs:line 161
at Microsoft.Bot.Builder.Dialogs.ComponentDialog.ContinueDialogAsync(DialogContext outerDc, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.Dialogs.DialogContext.ContinueDialogAsync(CancellationToken cancellationToken)
at Microsoft.Bot.Builder.Dialogs.DialogExtensions.RunAsync(Dialog dialog, ITurnContext turnContext, IStatePropertyAccessor`1 accessor, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.ActivityHandler.OnInvokeActivityAsync(ITurnContext`1 turnContext, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.Teams.TeamsActivityHandler.OnInvokeActivityAsync(ITurnContext`1 turnContext, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.ActivityHandler.OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken)
at SampleVA.Bots.DefaultActivityHandler`1.OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken) in D:\a\r1\a\_eva\build-artifact\eva\Bots\DefaultActivityHandler.cs:line 44
at Microsoft.Bot.Solutions.Middleware.EventDebuggerMiddleware.OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken)
at Microsoft.Bot.Solutions.Middleware.SetLocaleMiddleware.OnTurnAsync(ITurnContext context, NextDelegate next, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.ShowTypingMiddleware.OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.TranscriptLoggerMiddleware.OnTurnAsync(ITurnContext turnContext, NextDelegate nextTurn, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.TelemetryLoggerMiddleware.OnTurnAsync(ITurnContext context, NextDelegate nextTurn, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.Integration.ApplicationInsights.Core.TelemetryInitializerMiddleware.OnTurnAsync(ITurnContext context, NextDelegate nextTurn, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.BotFrameworkAdapter.TenantIdWorkaroundForTeamsMiddleware.OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.MiddlewareSet.ReceiveActivityWithStatusAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.BotAdapter.RunPipelineAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken)
latest versions of VA and Calendar skill samples being used.
Hi @davidmcgowan, I'm looking into this. Can you confirm it only happens when you have more than one skill connected to the VA?
Great thanks.
I can confirm this happens with either 1 or more skills. The skill used to test was the calendar skill sample.
Also worth noting that the issue is not observed when testing in the emulator or webchat with SSO enabled.
@lauren-mills Is there any update on this? I am facing the same issue, but, using sample skill bot instead of calendar skill. SSO is also enabled.
Just for reference that is how the end-to-end transaction looks like in Azure telemetry for an aforementioned problem.

I'm setting up the environment to reproduce this issue. Will update once I have something
Hello, have you been able to reproduce this issue?
Hi @davidmcgowan,
I've taken an initial look into this. I need to do some more digging to pinpoint exactly what path we're hitting in the underlying SDK code, but my first take is that this is a bug in the SDK - specifically, here: https://github.com/microsoft/botbuilder-dotnet/blob/3906c535b18978c475bb6bc7dc82590257f64fb8/libraries/Microsoft.Bot.Builder/BotFrameworkAdapter.cs#L539-L544
Based on your described scenario of having two skills connected, my initial suspicion is that we are getting into a state where we are triggering two Invoke activities (which is I believe used to communicate to connected Skills ultimately), and hitting the condition in the linked code within the adapter when the bot is attempting to send all of the activities created during its turn.
I'm going to continue digging to make sure I can pinpoint the exact conditions under which this is occurring, but I expect that we will transfer this issue to the microsoft/botbuilder-dotnet repo and have the SDK team take this one.
Apologies for the delays, and thanks for the continued patience while we investigate this!
Just to follow up on this, the SDK has now merged the necessary change that should address this underlying issue. Once a new version of the SDK has been released containing this fix, we will be sure to publish new versions of the Virtual Assistant templates that contain this fix.
We are currently targeting mid-November timeframe for the new SDK release, so expect our update to follow shortly after that.
Many thanks @peterinnesmsft.
This should be resolved with the latest version of the SDK 4.11.0.
Closing this per last comment
Most helpful comment
Hi @davidmcgowan,
I've taken an initial look into this. I need to do some more digging to pinpoint exactly what path we're hitting in the underlying SDK code, but my first take is that this is a bug in the SDK - specifically, here: https://github.com/microsoft/botbuilder-dotnet/blob/3906c535b18978c475bb6bc7dc82590257f64fb8/libraries/Microsoft.Bot.Builder/BotFrameworkAdapter.cs#L539-L544
Based on your described scenario of having two skills connected, my initial suspicion is that we are getting into a state where we are triggering two Invoke activities (which is I believe used to communicate to connected Skills ultimately), and hitting the condition in the linked code within the adapter when the bot is attempting to send all of the activities created during its turn.
I'm going to continue digging to make sure I can pinpoint the exact conditions under which this is occurring, but I expect that we will transfer this issue to the microsoft/botbuilder-dotnet repo and have the SDK team take this one.
Apologies for the delays, and thanks for the continued patience while we investigate this!