Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Miguel Lopez 15 posts 117 karma points
    Mar 23, 2023 @ 11:35
    Miguel Lopez
    0

    Contentment country list error

    I am using Contentment with Umbraco v10. When I use the Contentment DataList editor with data source as .NET countries or .NET Currencies, I got the folowing error:

    System.ArgumentException: Culture ID 4096 (0x1000) is a neutral culture; a region cannot be created from it. (Parameter 'culture')
    

    Having a closer look at the code I can see the CountriesDataListSource at this point:

    return CultureInfo
                    .GetCultures(CultureTypes.SpecificCultures)
                    .Select(x => new RegionInfo(x.LCID))
                    .DistinctBy(x => x.TwoLetterISORegionName)
                    .Where(x => x.TwoLetterISORegionName.Length == 2) // NOTE: Removes odd "countries" such as Caribbean (029), Europe (150), Latin America (419) and World (001).
                    .OrderBy(x => x.EnglishName)
                    .Select(x => new DataListItem
                    {
                        Name = x.EnglishName,
                        Value = x.TwoLetterISORegionName
                    });
    

    Apparently GetCultures() is returning neutral cultures that then break the code when trying to create the RegionInfo.

    Has anyone experienced this, or have any clue as how to solve this?

    Thanks.

  • Miguel Lopez 15 posts 117 karma points
    Mar 24, 2023 @ 10:35
    Miguel Lopez
    100

    Found the issue:

    inside a Render Controller we had:

    var region = RegionInfo("US");
    

    Changed it to:

    var region = RegionInfo("en-US");
    

    Apparently, trying to get the region by the country code only was causing the available specific cultures to be neutral cultures too. Not sure I understand why... maybe someone can come up with a reasonable explanation.

  • Huw Reddick 1741 posts 6104 karma points MVP c-trib
    Mar 24, 2023 @ 10:38
    Huw Reddick
    0

    probably because US is not a valid culture code.

  • Miguel Lopez 15 posts 117 karma points
    Mar 31, 2023 @ 12:42
    Miguel Lopez
    0

    It is not, although the RegionInfo method was working properly.

Please Sign in or register to post replies

Write your reply to:

Draft