Bug 54324 - TryParse incorrectly returns false
Summary: TryParse incorrectly returns false
Alias: None
Product: iOS
Classification: Xamarin
Component: BCL Class Libraries ()
Version: XI 10.8 (d15-1)
Hardware: PC Mac OS
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Marek Safar
Depends on:
Reported: 2017-03-31 09:37 UTC by Sebastian
Modified: 2017-04-04 07:50 UTC (History)
4 users (show)

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

SampleApp (8.98 KB, application/zip)
2017-03-31 09:37 UTC, Sebastian

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 Developer Community or GitHub 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 Sebastian 2017-03-31 09:37:58 UTC
Created attachment 21090 [details]

On a German iOS device, or a simulator configured with German language and region, the following code returns false, even so it should return true as it does in previous versions of Xamarin.iOS.

decimal.TryParse("12,45", System.Globalization.NumberStyles.AllowCurrencySymbol, System.Globalization.CultureInfo.CurrentCulture.NumberFormat, out enteredValue)

Steps to reproduce:

1) Start an iOS simulator and set the language to German and the region to Germany.
2) Run provided sample app. Enter "12,45" and hit enter.

Expected behavior: An alert appears with a success message.
Current behavior: An alert appears with a non-success message.

=== Xamarin Studio Enterprise ===

Version 6.2.1 (build 3)
Installation UUID: 7e36f40e-122f-4090-be39-a0ab2eed880e
	Mono 4.8.0 (mono-4.8.0-branch/e4a3cf3) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 408000495

=== NuGet ===


=== Xamarin.Profiler ===

Version: 1.2.1
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 8.3 (12169)
Build 8E162

=== Xamarin.Mac ===

Version: (Visual Studio Enterprise)

=== Xamarin.iOS ===

Version: (Visual Studio Enterprise)
Hash: e66c6f19
Branch: xcode8.3
Build date: 2017-03-28 00:48:33-0400

=== Xamarin.Android ===

Version: (Visual Studio Enterprise)
Android SDK: /Users/Sebastian/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
		5.0   (API level 21)
		6.0   (API level 23)
		7.0   (API level 24)
		7.1   (API level 25)

SDK Tools Version: 25.2.5
SDK Platform Tools Version: 25.0.3
SDK Build Tools Version: 25.0.2

Java SDK: /usr
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)

Android Designer EPL code available here:

=== Xamarin Android Player ===

Not Installed

=== Xamarin Inspector ===

Not Installed

=== Build Information ===

Release ID: 602010003
Git revision: 5217903c99e9d9c5d3caa2498fd66d607debac29
Build date: 2017-03-23 12:36:46-04
Xamarin addins: 2c96d252b353fce2e8b8fd20884eee70c16c7f32
Build lane: monodevelop-lion-cycle9

=== Operating System ===

Mac OS X 10.12.4
Darwin iMac.local 16.5.0 Darwin Kernel Version 16.5.0
    Fri Mar  3 16:52:33 PST 2017
    root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64
Comment 1 Sebastian 2017-03-31 10:06:10 UTC
Possible workaround is to use System.Globalization.NumberStyles.Currency instead of AllowCurrencySymbol.
Comment 2 Alex Soto [MSFT] 2017-04-01 22:47:46 UTC
I can confirm the described scenario using the attached sample
Comment 3 Marek Safar 2017-04-03 16:17:40 UTC
This works as expected. You are parsing a number but disallowing decimal points hence TryParse fails.
If you allow decimal point you get your "expected" result.

var x = decimal.TryParse("12,45", System.Globalization.NumberStyles.AllowCurrencySymbol | System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.CurrentCulture.NumberFormat, out enteredValue);
Comment 4 Sebastian 2017-04-04 07:50:04 UTC
I expected that "AllowCurrencySymbol" handles the input like a currency. Thus it allows decimal points. But you are right on a Windows console app the behavior is like you said.