InvalidCastException in Activity.GetChannelData
See original GitHub issueVersion
4.16.1
Describe the bug
System.InvalidCastException:
at System.Runtime.CompilerServices.CastHelpers.ChkCast_Helper (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Bot.Schema.Activity.GetChannelData (Microsoft.Bot.Schema, Version=4.16.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.Bot.Builder.TelemetryLoggerMiddleware.PopulateAdditionalChannelProperties (Microsoft.Bot.Builder, Version=4.16.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.Bot.Builder.TelemetryLoggerMiddleware.FillReceiveEventPropertiesAsync (Microsoft.Bot.Builder, Version=4.16.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.Bot.Builder.TelemetryLoggerMiddleware+<OnReceiveActivityAsync>d__8.MoveNext (Microsoft.Bot.Builder, Version=4.16.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Bot.Builder.TelemetryLoggerMiddleware+<OnTurnAsync>d__7.MoveNext (Microsoft.Bot.Builder, Version=4.16.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Bot.Builder.Integration.ApplicationInsights.Core.TelemetryInitializerMiddleware+<OnTurnAsync>d__4.MoveNext (Microsoft.Bot.Builder.Integration.ApplicationInsights.Core, Version=4.16.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Bot.Builder.RegisterClassMiddleware`1+<OnTurnAsync>d__7.MoveNext (Microsoft.Bot.Builder, Version=4.16.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Bot.Builder.MiddlewareSet+<ReceiveActivityWithStatusAsync>d__3.MoveNext (Microsoft.Bot.Builder, Version=4.16.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Bot.Builder.BotAdapter+<RunPipelineAsync>d__23.MoveNext (Microsoft.Bot.Builder, Version=4.16.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
To Reproduce
The 2 functions Microsoft.Bot.Builder.Teams.TeamsInfo.SendMessageToTeamsChannelAsync(ITurnContext turnContext, IActivity activity, string teamsChannelId, MicrosoftAppCredentials credentials, CancellationToken cancellationToken):Task<Tuple<ConversationReference,string>>
and Microsoft.Bot.Builder.Teams.TeamsInfo.SendMessageToTeamsChannelAsync(ITurnContext turnContext, IActivity activity, string teamsChannelId, string botAppId, CancellationToken cancellationToken):Task<Tuple<ConversationReference,string>>
both set the ConversationParameters.ChannelData to an anonymous class value, but the GetChannelData always assumes this to be a JToken or the exact type needed and Microsoft.Bot.Builder.TelemetryLoggerMiddleware.PopulateAdditionalChannelProperties calls this expecting TeamsChannelData
.
Steps to reproduce the behavior:
- Use any of the above 2 methods with telemetry enabled
Tracking Status
Dotnet SDK TODO
- PR
- Merged
Javascript SDK TODO
- PR
- Merged
Python SDK TODO
- PR
- Merged
Java SDK TODO
- PR
- Merged
Samples TODO
- PR
- Merged
Docs TODO
- PR
- Merged
Tools TODO
- PR
- Merged
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top GitHub Comments
Also in 4.17.2, and did confirm that copying the functions and changing to
ChannelData = new TeamsChannelData{ Channel = new (){ Id = teamsChannelId } }
makes the problem go awayFix is being addressed in pull request https://github.com/microsoft/botbuilder-dotnet/pull/6477