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.

InvalidCastException in Activity.GetChannelData

See original GitHub issue

Version

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:

  1. 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:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
davhdavhcommented, Sep 19, 2022

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 away

0reactions
ramfattahcommented, Sep 21, 2022

Fix is being addressed in pull request https://github.com/microsoft/botbuilder-dotnet/pull/6477

Read more comments on GitHub >

github_iconTop Results From Across the Web

AudioBuffer: getChannelData() method - Web APIs | MDN
The getChannelData() method of the AudioBuffer Interface returns a Float32Array containing the PCM data associated with the channel, ...
Read more >
API throws exception of System.InvalidCastException
I am trying to send data to my ag-grid, but it throws exception of:- An exception of type 'System.InvalidCastException' occurred in System.
Read more >
InvalidCastException Class (System)
Initializes a new instance of the InvalidCastException class with a specified error message.
Read more >
System.Private.CoreLib.dll
GetChannelData. Ansi based on Memory/File Scan (246c4952423b79596070d6d49e27e1bb205423256d94aebf55d8ad192f7c8e22.bin). GetClassID.
Read more >
Advanced .NET Remoting, Second Edition
you might run into serious troubles, ranging from InvalidCastExceptions to code that works in the development environment but doesn't work in the production ......
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