{"record":{"id":"16b56e754c91e82c","repo":"litedb-org/LiteDB","slug":"invalid-lcid-code","errorCode":null,"errorMessage":"Invalid LCID code","messagePattern":"Invalid LCID code","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"LiteDB/Utils/LCID.cs","lineNumber":457,"sourceCode":"            [31836] = \"chr-Cher\",\n            [31837] = \"iu-Latn\",\n            [31839] = \"tzm-Latn\",\n            [31847] = \"ff-Latn\",\n            [31848] = \"ha-Latn\",\n            [31878] = \"quc-Latn\",\n            [31890] = \"ku-Arab\"\n            #endregion\n        };\n\n        public static CultureInfo GetCulture(int lcid)\n        {\n            if (_mappings.TryGetValue(lcid, out var name))\n            {\n                return new CultureInfo(name);\n            }\n            else\n            {\n                throw new ArgumentException(\"Invalid LCID code\");\n            }\n        }\n\n        public static int GetLCID(string culture)\n        {\n            foreach(var item in _mappings)\n            {\n                if (item.Value == culture)\n                {\n                    return item.Key;\n                }\n            }\n\n            throw new LiteException(0, $\"Invalid culture name\");\n        }\n\n        /// <summary>\n        /// Get current system operation LCID culture","sourceCodeStart":439,"sourceCodeEnd":475,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Utils/LCID.cs#L439-L475","documentation":"Thrown by LCID.GetCulture(int lcid) when the supplied LCID integer is not present in the built-in _mappings dictionary. Unlike the others, this throws System.ArgumentException (not LiteException), so a generic catch(LiteException) will miss it. The mapping table is a fixed list of Windows LCID codes compiled into the class.","triggerScenarios":"Calling LCID.GetCulture with an LCID not in the static map; reading a collation LCID from a database/index that references a culture the runtime table doesn't carry; passing a user-supplied locale id without validation.","commonSituations":"An index created with a culture whose LCID isn't in this LiteDB build's table; cross-platform locale differences; custom/neutral locale IDs; version skew where the LCID table differs.","solutions":["Validate the LCID against LCID's known cultures before calling GetCulture, or catch ArgumentException.","Use a culture name (string) path (CultureInfo.GetCultureInfo) if the LCID table is incomplete for your locale.","Rebuild/re-index with a supported collation.","Update/extend the LCID mapping table if a legitimate code is missing."],"exampleFix":"// before\nvar c = LCID.GetCulture(userLcid); // throws ArgumentException if unknown\n\n// after\ntry { var c = LCID.GetCulture(userLcid); }\ncatch (ArgumentException) { c = CultureInfo.InvariantCulture; }","handlingStrategy":"validation","validationCode":"// validate before calling; fall back gracefully\nCultureInfo c;\ntry { c = LCID.GetCulture(lcid); }\ncatch (ArgumentException) { c = CultureInfo.InvariantCulture; }","typeGuard":null,"tryCatchPattern":"try { var c = LCID.GetCulture(lcid); }\ncatch (ArgumentException) {\n    // NOTE: not a LiteException - use a separate catch\n    c = CultureInfo.InvariantCulture;\n}","preventionTips":["Remember this throws ArgumentException, not LiteException.","Validate LCIDs against a known-good list before lookup.","Prefer culture-name-based APIs when available."],"tags":["locale","collation","argument-exception","validation"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}