Search Issue Tracker
By Design
Votes
0
Found in
2020.1.0a5
2020.3
2020.3.26f1
2021.2
2022.1
2022.2
Issue ID
1395582
Regression
Yes
[Mobile] System.Convert.ToSingle throws exception when using specific language on device
How to reproduce:
1. Download the attached project "Unity-ex.zip"
2. Set your mobile device language to Russian, French, Portuguese, or Polish
3. Build and Run on Android
4. Observe logs in Android logcat
Expected result: No exceptions are thrown and value "0.13" is converted to "13" or "0.13"
Actual result: Values are not converted and exception is printed:
Exception System.FormatException: Input string was not in a correct format.
at System.Number.ThrowOverflowOrFormatException (System.Boolean overflow, System.String overflowResourceKey) [0x0001a] in <255dd91c7bc04664a19c23cae337b20d>:0
at System.Number.ParseSingle (System.ReadOnlySpan`1[T] value, System.Globalization.NumberStyles styles, System.Globalization.NumberFormatInfo info) [0x00071] in <255dd91c7bc04664a19c23cae337b20d>:0
Reproducible with: 2020.1.0a5, 2020.3.26f1, 2021.2.8f1, 2022.1.0b3, 2022.2.0a2
Not reproducible with: 2019.4.34f1, 2020.1.0a4
Notes:
- Not reproducible on Standalone builds or Editor
- Reproducible on Android and iOS
- Reproducible with .NET Framework and .NET Standard 2.1 Api Compatibility Level
- Reproducible with these languages: Russian, French, Portuguese, Polish (might be more affected languages)
Comments (2)
-
Groble-Inc
Jan 19, 2022 14:35
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; Is it possible to solve this?
-
Groble-Inc
Jan 19, 2022 14:24
Should I use CultureInfo.InvariantCulture for all Convert.To functions?
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Invalid Blue value in MotionBlurMergeTilePass when objects move at certain speeds
- Physics Debugger displays mouse cursor ray casts when Game view is not open if Input System package is used
- “ArgumentException” error thrown when disabling all columns in Project Auditor's Multi-column panel context menu
- Errors are thrown and contextual menu does not open when right-clicking multiple mixed keyframes in Dopesheet
- Crash on MergeObjectCollection when repeatedly selecting a Prefab Asset in the Project Browser
Resolution Note:
Convert.ToSingle is culture specific function, you can reproduce the same issue in simple .NET application
CultureInfo.CurrentCulture = new CultureInfo("ru-RU");
Convert.ToSingle("0.13")
The proper fix, would be to do
Convert.ToSingle("0.13", CultureInfo.InvariantCulture) is it would language independent.