{"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/290d5ab72cc1102813fbc0406fb186ceadabc340/src/native/libs/System.Native.Browser/native/globalization-locale.ts#L48-L84","documentation":"The resolved locale display string (language + region joined by \"##\") is checked against dstMaxLength — the size of the destination buffer the native caller allocated. If localized names are verbose enough to exceed it, the function refuses to write a truncated result and throws. The catch marshals the message to .NET with dstLength=-1.","triggerScenarios":"A locale whose resolved display names in the target culture produce a combined string longer than the dstMaxLength buffer the runtime passed in.","commonSituations":"Cultures/scripts with long translated display names exceeding the native buffer; running against an older dotnet runtime version that allocates a smaller buffer than the current one.","solutions":["Update to a newer dotnet runtime, which allocates a larger destination buffer for locale info.","If invoking the native API directly, allocate a destination buffer at least as large as the longest expected display-name pair.","Catch the error in .NET and retry with the invariant (English) culture, which yields shorter names."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { localeInfo = GetLocaleInfo(locale, culture, buffer, bufferLen); }\ncatch { localeInfo = GetLocaleInfo(locale, \"en\" /* invariant-ish */, buffer, bufferLen); }","preventionTips":["Keep the dotnet runtime up to date; locale-info buffer sizes have increased in newer versions.","Provide an invariant (English) culture fallback, which yields shorter display names.","If calling the native API directly, size the destination buffer generously."],"tags":["globalization","buffer-overflow","locale"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}