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)
-
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
- Articulation Body with 'Revolute' Joint Type has erratic behavior when Upper Limit is set to above 360
- WebGL Player fails to render Scene when Terrain with Detail Mesh is added and WebGPU Graphics API is used
- Inconsistent errors are logged when different types are passed into the Query "Q<>" method in UIToolkit and the ancestor VisualElement is null
- Crash on GetMaterialPropertyByIndex when opening a specific Scene
- Discrepancies in the styling are present when using a TSS file instead of a USS file in custom EditorWindow
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.