{"record":{"id":"47ff0262c69377d5","repo":"dotnet/runtime","slug":"locale-info-for-locale-localename-exceeds-lengt-47ff02","errorCode":null,"errorMessage":"Locale info for locale=${localeName} exceeds length of ${dstMaxLength}.","messagePattern":"Locale info for locale=(.+?) exceeds length of (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/native/libs/System.Native.Browser/native/globalization-locale.ts","lineNumber":66,"sourceCode":"                        return 0 as any;\n                    }\n                    throw error;\n                }\n            } else {\n                throw error;\n            }\n        }\n        const localeInfo = {\n            LanguageName: languageName,\n            RegionName: regionName,\n        };\n        const result = Object.values(localeInfo).join(OUTER_SEPARATOR);\n\n        if (!result)\n            throw new Error(`Locale info for locale=${localeName} is null or empty.`);\n\n        if (result.length > dstMaxLength)\n            throw new Error(`Locale info for locale=${localeName} exceeds length of ${dstMaxLength}.`);\n\n        _ems_.dotnetBrowserUtilsExports.stringToUTF16(dst, dst + 2 * result.length, result);\n        _ems_.dotnetApi.setHeapI32(dstLength, result.length);\n        return 0 as any;\n    } catch (ex: any) {\n        _ems_.dotnetApi.setHeapI32(dstLength, -1);\n        return _ems_.dotnetBrowserUtilsExports.stringToUTF16Ptr(ex.toString());\n    }\n\n    function normalizeLocale(locale: string | null) {\n        if (!locale)\n            return undefined;\n        try {\n            locale = locale.toLocaleLowerCase().replace(\"_\", \"-\");\n            if (locale.startsWith(\"zh-\")) {\n                // browser does not recognize \"zh-chs\" and \"zh-cht\" as equivalents of \"zh-Hans\" \"zh-Hant\", we are helping, otherwise\n                // it would throw on getCanonicalLocales with \"RangeError: Incorrect locale information provided\"\n                locale = locale.replace(\"-chs\", \"-Hans\").replace(\"-cht\", \"-Hant\");","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/native/libs/System.Native.Browser/native/globalization-locale.ts#L48-L84","documentation":"The locale display info (LanguageName##RegionName) is written into a fixed-size destination buffer the runtime allocated (dstMaxLength bytes). If the resolved string is longer than that buffer the write would overflow, so this error is thrown instead. The runtime controls dstMaxLength based on its expected maximum locale-info length.","triggerScenarios":"Intl.DisplayNames produces unusually long language/region names (some localizations of region/language names are verbose) whose joined length exceeds the buffer the runtime pre-allocated for this locale-info call.","commonSituations":"A culture whose display names in the target UI language are long (compound language names, long region names); a runtime version that sized the buffer too small for a newly added locale; malformed cultureName producing an unexpectedly long lookup result.","solutions":["This is almost always a runtime/buffer-sizing bug rather than an app config issue; update the .NET runtime workload to a version with the corrected buffer size for locale info.","As a workaround, use a culture with shorter display names or a neutral culture (language only) so RegionName is omitted and the result is shorter.","Report the specific locale + cultureName pair that triggers it so the buffer constant in the runtime can be raised."],"exampleFix":"// before: long display names overflow the buffer\nCultureInfo.CurrentUICulture = new CultureInfo(\"culture-with-very-long-display-name\");\n\n// after: neutral culture produces a shorter result\nCultureInfo.CurrentUICulture = new CultureInfo(\"en\");","handlingStrategy":"fallback","validationCode":"// This is a runtime buffer-size limit; apps cannot resize it. Validate the\n// chosen culture produces reasonably short display names.\nfunction localeInfoLength(locale: string, culture: string): number {\n  try {\n    const parts = locale.split(\"-\");\n    const region = parts.length > 1 ? parts.pop() : undefined;\n    const lang = new Intl.DisplayNames([culture], { type: \"language\" }).of(parts.join(\"-\")) ?? \"\";\n    const reg = region ? new Intl.DisplayNames([culture], { type: \"region\" }).of(region) ?? \"\" : \"\";\n    return (lang + \"##\" + reg).length;\n  } catch {\n    return 0;\n  }\n}\n// If length looks large, prefer a neutral culture to shorten the result.","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Treat this as a runtime defect; update the .NET workload to a version with a corrected buffer size.","As a workaround, use a neutral (language-only) culture to shorten the result.","Avoid cultures with unusually long display-name localizations for the UI culture.","Report the locale/culture pair so the buffer constant can be adjusted."],"tags":["globalization","locale","buffer","i18n","overflow"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}