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

Cannot deserialize decimal with MessagePack and System.Text.Json #54

Closed
Sire opened this issue Sep 26, 2019 · 1 comment
Closed

Cannot deserialize decimal with MessagePack and System.Text.Json #54

Sire opened this issue Sep 26, 2019 · 1 comment

Comments

@Sire
Copy link

Sire commented Sep 26, 2019

Blazor.Extensions.SignalR cannot deserialize decimals using Blazor preview 9 (and System.Text.Json).

To reproduce, just add a decimal to the DemoData class in the test project and enable MessagePack:
In ChatComponent.cs add: opt.EnableMessagePack = true;
In (server) Startup.cs uncomment: .AddMessagePackProtocol();

Any ideas on how to fix this problem? I suspect it's because MessagePack and System.Text.Json are currently incompatible. Possibly related System.Text.Json bug.

A possible fix is to use switch to Newtonsoft instead of the new default System.Text.Json. Previous versions of Blazor.Extensions.SignalR and Blazor 0.9.0 worked fine when used with Newtonsoft as Json serializer. Any way we can make the extension method AddNewtonsoftJsonProtocol work again? Used on
.HubConnectionBuilder(JSRuntimeCurrent).WithUrl("/chathub", options).AddNewtonsoftJsonProtocol();

Exception:

blazor.webassembly.js:1 Uncaught (in promise) Error: System.Text.Json.JsonException: The JSON value could not be converted to System.Decimal. Path: $.Dec | LineNumber: 0 | BytePositionInLine: 42. ---> System.InvalidOperationException: Cannot get the value of a token type 'String' as a number.
  at System.Text.Json.Utf8JsonReader.TryGetDecimal (System.Decimal& value) <0x25a5d98 + 0x0002c> in <81e9245ca982431695a55cc67ffb3b86>:0 
  at System.Text.Json.Utf8JsonReader.GetDecimal () <0x25a5cc0 + 0x0000a> in <81e9245ca982431695a55cc67ffb3b86>:0 
  at System.Text.Json.Serialization.Converters.JsonConverterDecimal.Read (System.Text.Json.Utf8JsonReader& reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) <0x25a5c08 + 0x00004> in <81e9245ca982431695a55cc67ffb3b86>:0 
  at System.Text.Json.JsonPropertyInfoNotNullable`4[TClass,TDeclaredProperty,TRuntimeProperty,TConverter].OnRead (System.Text.Json.JsonTokenType tokenType, System.Text.Json.ReadStack& state, System.Text.Json.Utf8JsonReader& reader) <0x25a59d0 + 0x00070> in <81e9245ca982431695a55cc67ffb3b86>:0 
  at System.Text.Json.JsonPropertyInfo.Read (System.Text.Json.JsonTokenType tokenType, System.Text.Json.ReadStack& state, System.Text.Json.Utf8JsonReader& reader) <0x20b7938 + 0x00098> in <81e9245ca982431695a55cc67ffb3b86>:0 
  at System.Text.Json.JsonSerializer.HandleValue (System.Text.Json.JsonTokenType tokenType, System.Text.Json.JsonSerializerOptions options, System.Text.Json.Utf8JsonReader& reader, System.Text.Json.ReadStack& state) <0x20b70c0 + 0x000d0> in <81e9245ca982431695a55cc67ffb3b86>:0 
  at System.Text.Json.JsonSerializer.ReadCore (System.Text.Json.JsonSerializerOptions options, System.Text.Json.Utf8JsonReader& reader, System.Text.Json.ReadStack& readStack) <0x20b3ee8 + 0x000a0> in <81e9245ca982431695a55cc67ffb3b86>:0 
   --- End of inner exception stack trace ---
  at System.Text.Json.ThrowHelper.ReThrowWithPath (System.Text.Json.ReadStack& readStack, System.Text.Json.Utf8JsonReader& reader, System.Exception ex) <0x25ef9d0 + 0x00028> in <81e9245ca982431695a55cc67ffb3b86>:0 
  at System.Text.Json.JsonSerializer.ReadCore (System.Text.Json.JsonSerializerOptions options, System.Text.Json.Utf8JsonReader& reader, System.Text.Json.ReadStack& readStack) <0x20b3ee8 + 0x00340> in <81e9245ca982431695a55cc67ffb3b86>:0 
  at System.Text.Json.JsonSerializer.ReadCore (System.Type returnType, System.Text.Json.JsonSerializerOptions options, System.Text.Json.Utf8JsonReader& reader) <0x20a9df0 + 0x0003e> in <81e9245ca982431695a55cc67ffb3b86>:0 
  at System.Text.Json.JsonSerializer.ParseCore (System.String json, System.Type returnType, System.Text.Json.JsonSerializerOptions options) <0x20a5b00 + 0x00086> in <81e9245ca982431695a55cc67ffb3b86>:0 
  at System.Text.Json.JsonSerializer.Deserialize[TValue] (System.String json, System.Text.Json.JsonSerializerOptions options) <0x2591390 + 0x00022> in <81e9245ca982431695a55cc67ffb3b86>:0 
  at Blazor.Extensions.HubConnection+<>c__DisplayClass30_0`10[TResult1,TResult2,TResult3,TResult4,TResult5,TResult6,TResult7,TResult8,TResult9,TResult10].<On>b__0 (System.String[] payloads) <0x25910d0 + 0x000a8> in <c55a512ad88d4b5691739ffb720e5e8d>:0 
  at (wrapper delegate-invoke) System.Func`2[System.String[],System.Threading.Tasks.Task].invoke_TResult_T(string[])
  at Blazor.Extensions.HubMethodCallback.On (System.String[] payloads) <0x2505058 + 0x00014> in <c55a512ad88d4b5691739ffb720e5e8d>:0 
  at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x1c128d0 + 0x000d2> in <b455df9113dd49c5bfed215a721aae19>:0 
--- End of stack trace from previous location where exception was thrown ---

  at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.InvokeSynchronously (Microsoft.JSInterop.JSRuntime jsRuntime, Microsoft.JSInterop.Infrastructure.DotNetInvocationInfo& callInfo, Microsoft.JSInterop.Infrastructure.IDotNetObjectReference objectReference, System.String argsJson) <0x21d7068 + 0x0018a> in <b57783c7fafa47088562351a82800d2f>:0 
  at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.BeginInvokeDotNet (Microsoft.JSInterop.JSRuntime jsRuntime, Microsoft.JSInterop.Infrastructure.DotNetInvocationInfo invocationInfo, System.String argsJson) <0x2246838 + 0x000ba> in <b57783c7fafa47088562351a82800d2f>:0 
    at Object.endInvokeDotNetFromJS (http://localhost:61448/_framework/blazor.webassembly.js:1:7164)
    at Object.invokeJSFromDotNet (http://localhost:61448/_framework/blazor.webassembly.js:1:6790)
    at _mono_wasm_invoke_js_marshalled (http://localhost:61448/_framework/wasm/mono.js:1:176158)
    at wasm-function[6322]:0x129810
    at wasm-function[1962]:0x6063e
    at wasm-function[565]:0x12891
    at wasm-function[565]:0x12eca
    at wasm-function[565]:0x12c35
    at wasm-function[565]:0x12c35
    at wasm-function[565]:0x12eca
@galvesribeiro
Copy link
Member

Check the latest package as it is working as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants