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

Android

-

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)

  1. Response avatar

    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.

Comments (2)

  1. 124574e0240528954ce7179b8d21f7a3?d=mm

    Groble-Inc

    Jan 19, 2022 14:35

    CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; Is it possible to solve this?

  2. 124574e0240528954ce7179b8d21f7a3?d=mm

    Groble-Inc

    Jan 19, 2022 14:24

    Should I use CultureInfo.InvariantCulture for all Convert.To functions?

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.