Web Api properties of type long (Int64) are incorrectly serialized by some rounding #41463
Closed
1 task done
Labels
area-web-frameworks
*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Is there an existing issue for this?
Describe the bug
When a Web Api function returns a class with a property of type long (Int64) the value of the property is rounded. E.g. 9223372036854773406 becomes 9223372036854774000. The last four digits are changed from 3406 to 4000.
I have tested this with .Net 6 and .Net 7.
I have tested with both NewtonSoft and System.Text.Json and issue is with both. However, when I "manually" serialize with either Json framework the values are correct. This change in value seems to be something that happens in the Web Api between the function returns the value to the Web Api serializes.
Expected Behavior
The values are output correctly. I.e. value 9223372036854773406 is output as 9223372036854773406.
Steps To Reproduce
With Visual Studio Create a new WebApi project with controllers using .Net 6 or .Net 7.
Inside the WeatherForecastController.cs add the following code:
Run the project and execute the testids. See that the returned values are incorrect as described.
Additionally there is a Public GitHub Repo here that shows this issue:
https://github.com/AndersWangRask/DotNetWebApiLongSerializationBug
Exceptions (if any)
No response
.NET Version
Microsoft.AspNetCore.App 7.0.0-preview.3.22178.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Anything else?
No response
The text was updated successfully, but these errors were encountered: