Bug 4242 - JavaScriptSerializer should use invariant culture
Summary: JavaScriptSerializer should use invariant culture
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Web ()
Version: master
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-04-04 18:40 UTC by Denis Lebedenko
Modified: 2016-04-01 12:19 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and 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 Links.

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.

Related Links:

Description Denis Lebedenko 2012-04-04 18:40:25 UTC
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

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");

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

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

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

                string arrayJson = serializer.Serialize(array);

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



Expected the same output as on MS .NET:

Comment 1 mz 2012-05-23 04:30:14 UTC
JavaScriptDeserializer suffers the same problem.
Comment 2 Hari Menon 2015-01-05 15:09:42 UTC
Are there any changes to the status of this bug? 

I am facing the issues mentioned in this thread when trying to deserialize using System.Web.Script.Serialization.JavaScriptSerializer on Mono on Ubuntu.

Are there any known workarounds to make the JavaScriptSerializer serialize/deserialize using CultureInfo.InvariantCulture ?

Comment 3 Peter Hagen 2015-10-16 11:10:46 UTC
I think I ran into the same issue, with deserializing double, float and decimal values. This on with mono 4.0.4(.1)
Comment 4 Alexander Köplinger [MSFT] 2016-04-01 12:19:10 UTC
Fixed by merging pull request https://github.com/mono/mono/pull/1086.