Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosmos DB Throws "Unable to cast object of type 'System.Int64' to type 'System.Int32'" when Calling ContinueDialogAsync #1859

Closed
NiteLordz opened this issue May 3, 2019 · 9 comments · Fixed by #1867
Labels
4.4 April 15, 2019 Release bug Indicates an unexpected problem or an unintended behavior. P0 Must Fix. Release-blocker

Comments

@NiteLordz
Copy link

Github issues should be used for bugs and feature requests. Use Stack Overflow for general "how-to" questions.

Version

Microsoft.Bot.Builder v4.4.0

Describe the bug

When executing line

await dialogContext.ContinueDialogAsync(cancellationToken)

System.InvalidCastException is thrown with details "Unable to cast object of type 'System.Int64' to type 'System.Int32'"

To Reproduce

Steps to reproduce the behavior:
Using CosmosDB storage
Execute the first message, works fine
Upon the second message, calling ContinueDialogAsync(...) fails

Expected behavior

Give a clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Using MemoryStorage does not have this problem
Works fine in version 4.3.0

[bug]

@v-kydela
Copy link
Contributor

v-kydela commented May 3, 2019

@NiteLordz - Can you provide the code for the dialog you're running?

@cleemullins
Copy link
Contributor

@NiteLordz, can you provide the full Exception stack? I would love to see the stack trace.

Also, if you can provide code that replicates the issue, we can quickly track it down.

@cleemullins cleemullins added 4.5 4.5 release bug Indicates an unexpected problem or an unintended behavior. investigate Needs more information in order to proceed P0 Must Fix. Release-blocker labels May 3, 2019
@EricDahlvang
Copy link
Member

Stack Trace:

TestCosmosBot.TestCosmosBotBot:Error: Exception caught : System.InvalidCastException: Unable to cast object of type 'System.Int64' to type 'System.Int32'.
   at Microsoft.Bot.Builder.Dialogs.Prompt`1.ContinueDialogAsync(DialogContext dc, CancellationToken cancellationToken)
   at Microsoft.Bot.Builder.Dialogs.DialogContext.ContinueDialogAsync(CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder.Dialogs\DialogContext.cs:line 160
   at Microsoft.Bot.Builder.Dialogs.ComponentDialog.ContinueDialogAsync(DialogContext outerDc, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder.Dialogs\ComponentDialog.cs:line 86
   at Microsoft.Bot.Builder.Dialogs.DialogContext.ContinueDialogAsync(CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder.Dialogs\DialogContext.cs:line 160
   at TestCosmosBot.TestCosmosBotBot.OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken) in C:\Users\v-eridah\source\repos\TestCosmosBot\TestCosmosBot\TestCosmosBotBot.cs:line 125
   at Microsoft.Bot.Builder.BotFrameworkAdapter.TenantIdWorkaroundForTeamsMiddleware.OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder\BotFrameworkAdapter.cs:line 964
   at Microsoft.Bot.Builder.MiddlewareSet.ReceiveActivityWithStatusAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder\MiddlewareSet.cs:line 55
   at Microsoft.Bot.Builder.BotAdapter.RunPipelineAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder\BotAdapter.cs:line 167

@v-kydela
Copy link
Contributor

v-kydela commented May 3, 2019

Perhaps it's this cast right here: https://github.com/Microsoft/botbuilder-dotnet/blob/4.4/libraries/Microsoft.Bot.Builder.Dialogs/Prompts/Prompt.cs#L90

Perhaps CosmosDB stores the counter as an Int64 by default and so that's how it gets read.

@v-kydela
Copy link
Contributor

v-kydela commented May 3, 2019

That line was introduced very recently: https://github.com/Microsoft/botbuilder-dotnet/pull/1774/files#diff-1bbbc8f550395adfa5f014863009e56dR90

I presume the counter is being cast from an object to an integer so that arithmetic can be performed on it, but it wasn't considered what size of integer it should be. I wonder if there's some recommended way this kind of situation is meant to be handled. We could cast it as a long instead, or we could use Convert.ToInt32.

@EricDahlvang
Copy link
Member

https://github.com/Microsoft/botbuilder-dotnet/blob/master/libraries/Microsoft.Bot.Builder.Dialogs/WaterfallDialog.cs#L112

        // For issue https://github.com/Microsoft/botbuilder-dotnet/issues/871
        // See the linked issue for details. This issue was happening when using the CosmosDB
        // data store for state. The stepIndex which was an object being cast to an Int64
        // after deserialization was throwing an exception for not being Int32 datatype.
        // This change ensures the correct datatype conversion has been done.
        var index = Convert.ToInt32(state[StepIndex]);

EricDahlvang pushed a commit that referenced this issue May 3, 2019
EricDahlvang pushed a commit that referenced this issue May 3, 2019
EricDahlvang pushed a commit that referenced this issue May 3, 2019
@sgellock sgellock added 4.4 April 15, 2019 Release and removed 4.5 4.5 release labels May 3, 2019
@sgellock sgellock added Approved and removed investigate Needs more information in order to proceed labels May 3, 2019
@sgellock
Copy link
Member

sgellock commented May 3, 2019

we're cutting a 4.4.1 release of the C# SDK to address this issue.

@NiteLordz
Copy link
Author

Just confirmed this is now working in 4.4.1

Great work!

@EricDahlvang
Copy link
Member

Thank you for reporting this @NiteLordz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.4 April 15, 2019 Release bug Indicates an unexpected problem or an unintended behavior. P0 Must Fix. Release-blocker
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants