OverflowException: Value was either too large or too small for an unsigned byte.

I have used pseudo localization, and are using SmartExtensions.FormatSmart() to format this bellow string with arguments.
In english, it works fine, but on pseudo localization, it crashes on overflow exception:

System.Convert.ThrowByteOverflowException () (at <f67bbaca809f45d99c92519300368493>:0)
System.Convert.ToByte (System.Char value) (at <f67bbaca809f45d99c92519300368493>:0)
UnityEngine.Localization.SmartFormat.Core.Parsing.Parser.ParseFormat (System.String format, System.Collections.Generic.IList`1[T] formatterExtensionNames) (at ./Library/PackageCache/com.unity.localization@1.4.4/Runtime/Smart Format/Core/Parsing/Parser.cs:415)
UnityEngine.Localization.SmartFormat.SmartFormatter.Format (System.IFormatProvider provider, System.Collections.Generic.IList`1[T] args, System.String format) (at ./Library/PackageCache/com.unity.localization@1.4.4/Runtime/Smart Format/SmartFormatter.cs:194)
UnityEngine.Localization.SmartFormat.SmartFormatter.Format (System.String format, System.Object[ ] args) (at ./Library/PackageCache/com.unity.localization@1.4.4/Runtime/Smart Format/SmartFormatter.cs:156)
UnityEngine.Localization.SmartFormat.Smart.Format (System.String format, System.Object[ ] args) (at ./Library/PackageCache/com.unity.localization@1.4.4/Runtime/Smart Format/Smart.cs:15)
UnityEngine.Localization.SmartFormat.SmartExtensions.FormatSmart (System.String format, System.Object[ ] args) (at ./Library/PackageCache/com.unity.localization@1.4.4/Runtime/Smart Format/SmartExtensions.cs:59)```

**Text that I requested to smart format:**

[Åŕɱöŕ îš å šţåţ ýöûŕ ûñîţš öŕ éñéɱîéš çåñ ĥåṽé·
Åñý þĥýšîçåļ ðåɱåĝé ðéåļţ ţö å ûñîţ ţĥåţ ĥåš Åŕɱöŕ îš ŕéðûçéð ƀý {⓪}‰ (ðåɱåĝé ţéẋţ îš ĝŕåýéð öûţ)·
Ûñîţš ţĥåţ ĥåṽé Åŕɱöŕ Þéñéţŕåţîöñ îĝñöŕé Åŕɱöŕ åñð ðéåļ ƒûļļ ðåɱåĝé·
Ýöû çåñ ŕéåð ɱöŕé åƀöûţ Åŕɱöŕ Þéñéţŕåţîöñ öñ îţš öŵñ þåĝ鷞ݷ⅋ṽ∶ĵ⑧ẊĴŴƁ⅋‿}ẋ⁏ẋŔ♯ṽ‰≂ƀŠåẋ⁎Ž‰ĜŕÇ⅋{③Ǫ⑧ĝ⁎ĝ,Ŕ´ñṼ{ÉŴûÛŔéĜĻ,Å④″)≂}Å①îÎ}ŵîĵĥ‐‿՞Ĝžĵ④ŕƒÞ⑦ñ]

I presume this is because the format argument {0} was replaced by **{⓪}.** I think pseudo localization should check for this things and not replace the standarized formatting expressions, as even when translating text to different languages, these expressions are not touched.

That’s strange. Pseudo localization should be applied after smart formatting.
Could you please file a bug report?

You can add the preserve tag method to stop smart format tags being changed. https://docs.unity3d.com/Packages/com.unity.localization@1.4/manual/Pseudo-Localization-Methods.html

but the issue is not with rich text tags like , but rather with {0} c# formatting markers.
So regular c# method like String.Format() can accept {0} to format it, for example:

String result = String.Format(value, 5);
// Outsome is: "This is number 5 five";```

but what psuedo localization will do is:

```String value = "Ţĥîš îš ƀŕöŵñ {⓪} šţŕîñĝ·";
String result = String.Format(value, 5); <= CRASH HERE, as the "value" does not contain valid {0} marker for number 5 parameter.```

We apply pseudo localization after the String.Format call. Are you doing your own formatting?

The preserve tags method can be configured to ignore string formatting tags
9199658--1282997--upload_2023-8-7_10-35-15.png

@ -jo For some reason its still not working.
Yes I use custom code to use this method to format my texts.

This is the input string for the SmartExtensions.FormatSmart() method
[Åŕɱöŕ Þéñéţŕåţîöñ îš å šţåţ ýöûŕ ûñîţš öŕ éñéɱîéš çåñ ĥåṽé·
Ŵĥéñ å ûñîţ ĥåš åŕɱöŕ þéñéţŕåţîöñ, îţ ŵîļļ ðéåļ ƒûļļ ðåɱåĝé ţö éñéɱîéš ţĥåţ ĥåṽé åŕɱöŕ, åš ûñîţš ŵîţĥ åŕɱöŕ ţåķé {0}‰ ŕéðûçéð þĥýšîçåļ ðåɱåĝé·
Ƒöŕ éẋåɱþļé, Öŕç Ɓéŕšéŕķéŕš ĥåš Åŕɱöŕ šţåţ· Ŵĥéñ ýöûŕ åŕçĥéŕ ðéåļš ðåɱåĝé, ðåɱåĝé ţö ţĥé öŕç îš ŕéðûçéð (ðåɱåĝé ţéẋţ îš ĝŕåýéð öûţ)·
Ĥöŵéṽéŕ ýöûŕ Åẋéɱåñ ûñîţ ĥåš Åŕɱöŕ Þéñéţŕåţîöñ, šö îţ ŵîļļ ðéåļ ƒûļļ ðåɱåĝé ţö ţĥîš öŕç·
Ŕéåð ɱöŕé åƀöûţ Åŕɱöŕ îñ Åŕɱöŕ þåĝé· Åñð ƀé çåŕéƒûļļ, åš ýöûŕ éñéɱîéš ɱåý åļšö ĥåṽé Åŕɱöŕ Þéñéţŕåţîöñ, þéñéţŕåţîñĝ åŕɱöŕ öƒ ýöûŕ ûñîţš ļîķé Ķñîĝĥţš öŕ Þåļåðîñš·ŵɱû≤ñĻŠé④Åļŵ{∶ļ)Ĝ≤Ţ⅋ẋ¿Ẋå¿Î″é②玃Ṽ⑧∶(ðẋĤ€Ẋ⑨·ŵç∶Ö}Ṁ≤∶(⑦ţ⑤⓪ĥ②ŢÇƀ④Ĥ⁏Ý€Ţƒ⑧Ç,‰åĜ˄Çŵţ②ÞƑ‐⁄Û‿Ž②Ö∶‐ÐƀķŽ♯ķ③ý€ƀÎ≤ŵÉ՞ÎåĶåĴðå¿ð⑤éĵñ⁺∶¡ṼṽṀ·ûŴ⁅¡ĶÑ①ĜÎŵ⁏·⁅{Ƒ)Ļŵð③ţ⑥šƒ¦Š⑦{④}≥ç·ļ⁆⁺žûŵļЉƁ①¡‿þ⁏ŕðƒ⑧].

This is the method I use to manually format:

public static string GetLocalizedStringSmart(this LocalizedString str)
        {
            string localizedString = str.GetLocalizedString();
            if (str.Values.Count == 0)
            {
                return localizedString;
            }
     
            object[] array = new object[str.Values.Count];
            int i = 0;
            foreach (IVariable variable in str.Values)
            {
                array[i++] = variable.GetSourceValue(null);
            }

            string formatSmart = localizedString;

            try
            {
                formatSmart = localizedString.FormatSmart(array);
            }
            catch (Exception e)
            {
                Debug.Log($"Failed to smart format text: {formatSmart}." +
                          $"\nArguments: {TextUtils.ArrayToString(array)}" +
                          $"\nException: {e.Message}");
            }

            return formatSmart;
        }

There is one number in the array, just 25, and it still throws an exception

But you can see that tag is preserved on the above picture, as I have added the preserve tags:

9199751--1283033--upload_2023-8-7_12-9-2.png

We are using this custom method, because of the issue with UI I have reported in previous suggestions thread, that each language requires to be marked as “smart”, thats why we cannot use just LocalizedString.GetLocalizedString() API.

It sounds like the issue is with the data you are passing in with array. Try printing out the value of array[0], maybe theres something wrong with that value?

I did and showed it in my reply, its 25 (please take a look at the console output, red arrow)
9202644--1283670--upload_2023-8-8_17-18-10.png

as this is how I print this output:
9202644--1283676--upload_2023-8-8_17-18-55.png

it includes the formatted array with values

Ah sorry I missed that. I can see the issue now, the pseudo localization has added in some { and } characters which confused the system.
So the issue is not the preserving of the old tags but the introduction of new ones.

If you want to always use smart format and not have to set them then you could force it before calling GetLocalizedString.
E.G

public static string GetLocalizedStringSmart(this LocalizedString str)
{
    // Force the table entry to be marked as smart.
    var result = LocalizationSettings.StringDatabase.GetTableEntry(str.TableReference, str.TableEntryReference);
    result.Entry.IsSmart = true;

    return str.GetLocalizedString();
}

Alternatively, adjust the pseudo locale so that it replaces any {} characters.
E.G

9202725--1283694--upload_2023-8-8_16-38-20.png

It will still preserve the original ones and only remove any that it may have added.