This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 4242 - JavaScriptSerializer should use invariant culture
: JavaScriptSerializer should use invariant culture
Status: NEW
Product: Class Libraries
Classification: Mono
Component: Sys.Web
: Trunk
: PC Linux
: --- normal
: ---
Assigned To: Bugzilla
:
:
:
:
  Show dependency treegraph
 
Reported: 2012-04-04 18:40 EDT by Denis Lebedenko
Modified: 2012-05-23 04:30 EDT (History)
2 users (show)

See Also:
Tags:
Test Case URL:
External Submit: ---


Attachments

Description Denis Lebedenko 2012-04-04 18:40:25 EDT
It seems that the System.Web.Script.Serialization.JavaScriptSerializer class
from the System.Web.Extensions assembly is using the current culture instead of
the invariant culture for serialization and deserialization. This leads to
incorrectly serialized floating-point numbers on cultures that use comma
instead of a point as the decimal symbol.

Mono versions: Git 5091f779533227461caef216b56ccad071bd6cab, Debian 2.10.8.1-1

Steps to reproduce:

[mono] /tmp/serializationtest @ cat test.cs
using System;
using System.Globalization;
using System.Threading;
using System.Web.Script.Serialization;

class Program
{
        static void Main()
        {
                Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
                Test();

                Thread.CurrentThread.CurrentCulture = new CultureInfo("lt-LT");
                Test();
        }

        static void Test()
        {
                JavaScriptSerializer serializer = new JavaScriptSerializer();

                double[] array = new[] { 123.456, 0.78901 };

                string arrayJson = serializer.Serialize(array);
                Console.WriteLine(arrayJson);

        }
}
[mono] /tmp/serializationtest @ dmcs test.cs -r:System.Web.Extensions
[mono] /tmp/serializationtest @ mono test.exe

Output:

[123.456,0.78901]
[123,456,0,78901]

Expected the same output as on MS .NET:

[123.456,0.78901]
[123.456,0.78901]
Comment 1 mz 2012-05-23 04:30:14 EDT
JavaScriptDeserializer suffers the same problem.

Note You need to log in before you can comment on or make changes to this bug.