Skip to content

InvariantGlobalization causes TryConvertCoinsValue to fail #134

@Homosanians

Description

@Homosanians

InvariantGlobalization causes TryConvertCoinsValue to fail. A call within such assembly is not compatible with current Coins implementation. The globalization-invariant mode means that the application doesn't have access to specific culture information except for the invariant one.

InvariantGlobalization .csproj setting:

    <PropertyGroup>
        <InvariantGlobalization>true</InvariantGlobalization>
    </PropertyGroup>

Exception thrown:

Only the invariant culture is supported in globalization-invariant mode. See https://aka.ms/GlobalizationInvariantMode for more information. (Parameter 'name')
en-US is an invalid culture identifier.

TonSdk.NET code causing issue:

    private static bool TryConvertCoinsValue(object value, out Decimal result)
    {
        result = 0M;
        try
        {
            if (Decimal.TryParse(value.ToString(), NumberStyles.Any, (IFormatProvider) new CultureInfo("en-US"), out result))
                return true;
            double result1;
            if (!double.TryParse(value.ToString(), NumberStyles.Any, (IFormatProvider) new CultureInfo("en-US"), out result1))
                return false;
            result = (Decimal) result1;
            return true;
        }
        catch
        {
            return false;
        }
    }

POC:

Csproj code running in

  • added <InvariantGlobalization>false</InvariantGlobalization> to .csproj

Code:

new Coins(0.01m),

Results:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions