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
SignalR with Messagepack: JavaScript Number to C# Double Precision Loss #20333
Comments
I'm giving a bit more information here: msgpack5 by default doesn't force
There's an option to force that to happen, but @microsoft/signalr-protocol-msgpack doesn't allow access to it. In browser console:
This works:
|
This sounds like something that can't really be avoided to some degree. Serializing floating point numbers is a tricky thing and JavaScript and C# don't necessary have the same encoding rules. You could serialize it as a
This seems like the relevant thing to fix here. We should provide access to the msgpack configuration options. Let's track that work here and leave this open. |
As an experiment I hacked |
I have created a PR here with a proposed solution for exposing the underlying msgpack configuration options: #20438 |
Done via #20438 |
Describe the bug
When serializing and deserializing values between JavaScript and C# using SignalR with MessagePack I am seeing a bit of precision loss in C# on the receiving end.
As an example I am sending the value 0.005 from JavaScript to C#. When the deserialized value appears on the C# side I am getting the value 0.004999999888241291, which is close, but not 0.005 exactly. The value on the JavaScript side is Number and on the C# side I am using double.
I am wondering if there is a way using binary serialization to have matching values on both sides.
If not, does this mean that there is no way to have 100% accurate binary conversions between JavaScript and C#?
SO post for reference: https://stackoverflow.com/questions/60892286/javascript-to-c-sharp-numeric-precision-loss/60921624?noredirect=1#comment107818772_60921624
To Reproduce
What steps can we follow to reproduce the issue?
Followed the steps in this tutorial: https://docs.microsoft.com/en-us/aspnet/core/signalr/messagepackhubprotocol?view=aspnetcore-3.1
Only difference is that I am using
ContractlessStandardResolver.Instance
Further technical details
dotnet --info
The text was updated successfully, but these errors were encountered: