microsoft / botbuilder-dotnet

Welcome to the Bot Framework SDK for .NET repository, which is the home for the libraries and packages that enable developers to build sophisticated bot applications using .NET.
https://github.com/Microsoft/botframework
MIT License
878 stars 484 forks source link

CosmosDB appears to convert Int32 objects to Int64 #959

Closed JonathanFingold closed 6 years ago

JonathanFingold commented 6 years ago

Using an IPropertyAccessor with CosmosDB as the storage layer in ASP.NET Core causes exceptions.

Repo steps: Modify the 2.EchoBotWithCounter v4 sample:

Error information:

EchoBotWithCounter> fail: Microsoft.BotBuilderSamples.EchoWithCounterBot[0]
EchoBotWithCounter>       Exception caught : System.InvalidCastException: Unable to cast object of type 'System.Int64' to type 'System.Int32'.
EchoBotWithCounter>          at Microsoft.Bot.Builder.BotState.GetPropertyValueAsync[T](ITurnContext turnContext, String propertyName, CancellationToken cancellationToken) in D:\a\1\s\libraries\Microsoft.Bot.Builder\BotState.cs:line 180
EchoBotWithCounter>          at Microsoft.Bot.Builder.BotState.BotStatePropertyAccessor`1.<GetAsync>d__7.MoveNext() in D:\a\1\s\libraries\Microsoft.Bot.Builder\BotState.cs:line 314
EchoBotWithCounter>       --- End of stack trace from previous location where exception was thrown ---
EchoBotWithCounter>          at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
EchoBotWithCounter>          at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
EchoBotWithCounter>          at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
EchoBotWithCounter>          at Microsoft.BotBuilderSamples.EchoWithCounterBot.<OnTurnAsync>d__3.MoveNext() in C:\Users\v-jofing\source\repos\BotBuilder-Samples\csharp_dotnetcore\2.EchoBot-With-Counter\EchoWithCounterBot.cs:line 64
EchoBotWithCounter>       --- End of stack trace from previous location where exception was thrown ---
EchoBotWithCounter>          at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
EchoBotWithCounter>          at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
EchoBotWithCounter>          at Microsoft.Bot.Builder.MiddlewareSet.<ReceiveActivityWithStatusAsync>d__3.MoveNext() in D:\a\1\s\libraries\Microsoft.Bot.Builder\MiddlewareSet.cs:line 55
EchoBotWithCounter>       --- End of stack trace from previous location where exception was thrown ---
EchoBotWithCounter>          at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
EchoBotWithCounter>          at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
EchoBotWithCounter>          at Microsoft.Bot.Builder.BotAdapter.<RunPipelineAsync>d__13.MoveNext() in D:\a\1\s\libraries\Microsoft.Bot.Builder\BotAdapter.cs:line 167
EchoBotWithCounter> info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
EchoBotWithCounter>       Request finished in 292.4943ms 200 
JonathanFingold commented 6 years ago

PS. You need to add the following line to the bot's .cs file before saving to storage because our state object is a value type:

await _accessors.CounterAccessor.SetAsync(turnContext, count);
drub0y commented 6 years ago

This is the same problem as #871 just rearing its head in a diff way.

sgellock commented 6 years ago

871 #891, fix merged into master.