Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
GitHub or Developer Community with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Created attachment 7484 [details]
Test code to replicate the error
Attached to this bug report is a test program that replicates this bug.
Steps to reproduce:
Suppose you have a System.IO.Stream containing a JSON string that contains at least one floating-point number (e.g. the JSON string "42.42"). Deserialize that string using an instance of the System.Runtime.Serialization.Json.DataContractJsonSerializer class using System.Object as type-information (NOT one of the CLR floating-point datatypes!).
Current buggy behaviour:
The call to ReadObject(System.IO.Stream) of the created System.Runtime.Serialization.Json.DataContractJsonSerializer instance throws a System.Runtime.Serialization.SerializationException.
Behaviour in the .NET framework:
The call to ReadObject(System.IO.Stream) successfully deserializes the stream to an object value. The floating-point value is actually a System.Decimal value that is boxed in a System.Object instance.
I discovered this bug when I attempted to deserialize the JSON response of a web-service that returns the fields of a data as a JSON array where each element is a field of the returned data row. In that case I have to deserialize the response with System.Object as the type parameter passed to the System.Runtime.Serialization.Json.DataContractJsonSerializer constructor. This works fine in the .NET framework in Windows, but Mono fails to do this.
As I browsed through the source code of the Mono implementation I discovered that the ReadInstanceDrivenObject() method of the System.Runtime.Serialization.Json.JsonSerializationReader class uses a series of TryParse calls when it recognizes the JSON value as JSON number type. The calls to the TryParse functions all use System.Globalization.NumberStyles.None as the second argument, however, and that is the problem.
Quote from http://msdn.microsoft.com/en-us/library/system.globalization.numberstyles.aspx :
System.Globalization.NumberStyles.None: Indicates that no style elements, such as leading or trailing white space, thousands separators, or a decimal separator, can be present in the parsed string. The string to be parsed must consist of integral decimal digits only.
The ReadInstanceDrivenObject() method should use System.Globalization.NumberStyles.Integer for the interger types, and System.Globalization.NumberStyles.Float for the floating-point types.
The file attached file test.cs can be compiled to test.exe using the following command:
mcs -r:System.Runtime.Serialization test.cs
In the Ubuntu source package the implementation of the System.Runtime.Serialization.Json.JsonSerializationReader class can be found at the following location:
Created attachment 7485 [details]
Proposed bugfix containing only changes made to the buggy method
Thank you for the detailed bug report.
The pull request for this issue can be found in the link below.
Fixed in master 410af9c0cc1b781cbe434d4706411f67a28b5eb9.