Closed samcov closed 5 years ago
In 3.0 the default hub protocol was changed from using Newtonsoft.Json to System.Text.Json. There are many differences between the two libraries. If you would like to switch back to using Newtonsoft.Json then you can do so by following the docs: https://docs.microsoft.com/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio#switch-to-newtonsoftjson
@BrennanConroy That was the problem, following the directions in the docs resolved my issue. I'll want to use the default in the future, but it seems to have radically different behavior.
Either way, many thanks to you for recognizing the problem and supplying a solution!
Basic Issue: In .net Core 2.2, passing an array into a hub method maintained the expected type, in 3.0, the type for strings is not preserver when getting the type via GetType, but shows up properly in debugging.
I expect a string, but I get {Name = "JsonElement" FullName = "System.Text.Json.JsonElement"}
View of the Hub Method: public async Task
It's the parameters we want to inspect because we want to do type conversion to match the signature of the function being called.
However, when we do the following, if (value.GetType() == targetType), where target type is string, we see value as string in debugging, but the result of applying GetType is as shown above.
This does not happen in .net core 2.2, GetType returns a string.
I actually believe the 3.0 version is correct, but this is a breaking change if we have to handle Json elements as well as normal situations.