Bug 57496 - [Slovenian CultureInfo + others] .Parse throws exception when parsing negative values
Summary: [Slovenian CultureInfo + others] .Parse throws exception when parsing negativ...
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib (show other bugs)
Version: unspecified
Hardware: PC All
: --- normal
Target Milestone: Future Release
Assignee: Marek Safar
Depends on:
Reported: 2017-06-14 17:03 UTC by Iztok Delfin
Modified: 2017-09-13 11:50 UTC (History)
4 users (show)

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

ParseTest xamarin.android solution (184.46 KB, application/x-zip-compressed)
2017-06-14 17:03 UTC, Iztok Delfin

Description Iztok Delfin 2017-06-14 17:03:42 UTC
Created attachment 22889 [details]
ParseTest xamarin.android solution

For Slovenian CultureInfo and others (Urdu,Arabic,Pashto)
The following code throws an exception "Input string was not in a correct format." :

int.Parse("-1", NumberFormatInfo.GetInstance(cultureInfo)); 

Probably Duplicate of https://bugzilla.xamarin.com/show_bug.cgi?id=14185 as all the CultureInfos that throw an exception have a different negative sign value than the invariant and other, working cultureInfos.

See attached demo Xamarin.Android project for detailed info.
Comment 1 Jerdna 2017-08-09 10:37:45 UTC
We are also facing the same issue with Slovenian culture info.

Can you please change importance to highest? The problem is, we cannot upgrade Xamarin till this bug is resolved, because our app will become unstable. Also we dont want to use workarounds for ex. Convert.ToInt32 or similar.
Comment 2 Iztok Delfin 2017-08-09 12:26:00 UTC
I cannot do that as a user. Hopefully someone from the team will pick up the ticket soon and assign appropriate priority to it.
Comment 3 Marek Safar 2017-09-12 14:03:09 UTC
Console repro

using System;
using System.Globalization;

class MainClass
	public static void Main (string [] args)
		CultureInfo culture = null;
		for (int i = 1; i < 30000; i++) {
			try {
				try {
					culture = CultureInfo.GetCultureInfo (i);
				} catch {
					// non-existent LCIDs are passed over.

				int.Parse ("-1", NumberFormatInfo.GetInstance (culture));
				//Uncomment to see all the working ones. They all have \u002D number sign.
				//Console.WriteLine($"WORKING - LCID: {i} , Culture Info: {culture.DisplayName} , Negative sign: \\u{((int)culture.NumberFormat.NegativeSign[0]).ToString("X4")} , NumberNegativePattern: {culture.NumberFormat.NumberNegativePattern}");

			} catch (Exception ex) {
				Console.WriteLine ($"ERROR - LCID: {i} , Culture Info: {culture.DisplayName} , Negative sign: \\u{((int)culture.NumberFormat.NegativeSign [0]).ToString ("X4")} , NumberNegativePattern: {culture.NumberFormat.NumberNegativePattern} , Exception message: {ex.Message}");
Comment 4 Marek Safar 2017-09-13 11:50:33 UTC
Fixed in master/2017-08/2017-06 branches

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