litedb-org/LiteDB · error · LiteException

0

0

Error message

Invalid culture name

What it means

Thrown by LCID.GetLCID(string culture) when the supplied culture name (e.g. 'en-US') is not found by reverse lookup in the _mappings dictionary. It performs a linear search of values and throws LiteException if none matches. Only cultures explicitly listed in the table resolve.

Solutions

  1. Pass the exact culture string as listed in the LCID table (correct case and region suffix).
  2. Validate/fall back: try CultureInfo.GetCultureInfo(name) and resolve its LCID via the framework instead.
  3. Normalize the name (canonicalize case) before lookup.
  4. Re-create the index with a supported collation name.

Example fix

// before
var id = LCID.GetLCID("en-us"); // case mismatch -> throws

// after
var id = LCID.GetLCID(CultureInfo.GetCultureInfo("en-us").Name); // 'en-US'
Defensive patterns

Strategy: validation

Validate before calling

// canonicalize via the framework first, then look up
var name = CultureInfo.GetCultureInfo(culture).Name; // normalizes case/region
int lcid = LCID.GetLCID(name);

Try / catch

try { int id = LCID.GetLCID(culture); }
catch (LiteException ex) when (ex.Message.Contains("Invalid culture name")) {
    // normalize/validate the name, or fall back to invariant
}

Prevention

When it happens

Trigger: Calling LCID.GetLCID with a culture name absent from the built-in table; passing a custom/neutral/mis-cased name (lookup is case-/exact-sensitive: 'en-us' won't match 'en-US'); reading a collation name not in this build.

Common situations: Mismatched casing or region suffix; locale names produced by a different runtime than the table; indexes referencing a collation whose name isn't mapped; version skew in the LCID table.

Related errors


AI-assisted analysis of litedb-org/LiteDB@f906a5f850 (2026-08-13). Data as JSON: /api/errors/54c0ea0d5404856e. Report an issue: GitHub.

Appendix: source

Thrown at LiteDB/Utils/LCID.cs:471

                return new CultureInfo(name);
            }
            else
            {
                throw new ArgumentException("Invalid LCID code");
            }
        }

        public static int GetLCID(string culture)
        {
            foreach(var item in _mappings)
            {
                if (item.Value == culture)
                {
                    return item.Key;
                }
            }

            throw new LiteException(0, $"Invalid culture name");
        }

        /// <summary>
        /// Get current system operation LCID culture
        /// </summary>
        public static int Current
        {
            get
            {
                var current = CultureInfo.CurrentCulture.Name;

                var lcid = _mappings.FirstOrDefault(x => x.Value == current);

                // for 4096 culture LCID, returns 127 (invariant culture)
                if (lcid.Key == 0)
                {
                    return 127;
                }

View on GitHub (pinned to f906a5f850)