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
- var VisionOSEDRHeadromm has a comma instead of a dot when building with Metal Rendering App Mode and local OS localization is set to German
- IAP Catalog remove product “x” and add product “+” buttons are not consistent with other remove and add buttons in the Editor
- Performance issues in Play Mode when quickly hovering the mouse cursor over Hierarchy GameObjects
- Frame Debugger displays incorrect output when FidelityFX Super Resolution or Spatial-Temporal Upscaler is used with Temporal Anti-aliasing or Subpixel Morphological Anti-aliasing
- The layout system is failing to correctly calculate or apply the height of the Japanese fallback font when the primary English font's metrics are used
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.