dotnet/runtime · error · Error
Locale info for locale=${localeName} exceeds length of ${dst
Error message
Locale info for locale=${localeName} exceeds length of ${dstMaxLength}. What it means
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.
Source
Thrown at src/native/libs/System.Native.Browser/native/globalization-locale.ts:66
return 0 as any;
}
throw error;
}
} else {
throw error;
}
}
const localeInfo = {
LanguageName: languageName,
RegionName: regionName,
};
const result = Object.values(localeInfo).join(OUTER_SEPARATOR);
if (!result)
throw new Error(`Locale info for locale=${localeName} is null or empty.`);
if (result.length > dstMaxLength)
throw new Error(`Locale info for locale=${localeName} exceeds length of ${dstMaxLength}.`);
_ems_.dotnetBrowserUtilsExports.stringToUTF16(dst, dst + 2 * result.length, result);
_ems_.dotnetApi.setHeapI32(dstLength, result.length);
return 0 as any;
} catch (ex: any) {
_ems_.dotnetApi.setHeapI32(dstLength, -1);
return _ems_.dotnetBrowserUtilsExports.stringToUTF16Ptr(ex.toString());
}
function normalizeLocale(locale: string | null) {
if (!locale)
return undefined;
try {
locale = locale.toLocaleLowerCase().replace("_", "-");
if (locale.startsWith("zh-")) {
// browser does not recognize "zh-chs" and "zh-cht" as equivalents of "zh-Hans" "zh-Hant", we are helping, otherwise
// it would throw on getCanonicalLocales with "RangeError: Incorrect locale information provided"
locale = locale.replace("-chs", "-Hans").replace("-cht", "-Hant");View on GitHub (pinned to 290d5ab72c)
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.
Defensive patterns
Strategy: fallback
Try / catch
try { localeInfo = GetLocaleInfo(locale, culture, buffer, bufferLen); }
catch { localeInfo = GetLocaleInfo(locale, "en" /* invariant-ish */, buffer, bufferLen); } Prevention
- 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.
When it happens
Trigger: A locale whose resolved display names in the target culture produce a combined string longer than the dstMaxLength buffer the runtime passed in.
Common situations: 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.
Related errors
- Locale or culture name is null or empty. localeName=${locale
- Locale info for locale=${localeName} is null or empty.
- Locale info for locale=${localeName} exceeds length of ${dst
- Locale or culture name is null or empty. localeName=${locale
- Locale info for locale=${localeName} is null or empty.
AI-assisted analysis of dotnet/runtime@290d5ab72c (2026-08-06).
Data as JSON: /api/errors/47ff0262c69377d5.
Report an issue: GitHub.