dotnet/runtime · error · Error

Locale info for locale=

Error message

Locale info for locale=${localeName} exceeds length of ${dstMaxLength}.

What it means

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.

Solutions

  1. 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.
  2. 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.
  3. Report the specific locale + cultureName pair that triggers it so the buffer constant in the runtime can be raised.

Example fix

// before: long display names overflow the buffer
CultureInfo.CurrentUICulture = new CultureInfo("culture-with-very-long-display-name");

// after: neutral culture produces a shorter result
CultureInfo.CurrentUICulture = new CultureInfo("en");
Defensive patterns

Strategy: fallback

Validate before calling

// This is a runtime buffer-size limit; apps cannot resize it. Validate the
// chosen culture produces reasonably short display names.
function localeInfoLength(locale: string, culture: string): number {
  try {
    const parts = locale.split("-");
    const region = parts.length > 1 ? parts.pop() : undefined;
    const lang = new Intl.DisplayNames([culture], { type: "language" }).of(parts.join("-")) ?? "";
    const reg = region ? new Intl.DisplayNames([culture], { type: "region" }).of(region) ?? "" : "";
    return (lang + "##" + reg).length;
  } catch {
    return 0;
  }
}
// If length looks large, prefer a neutral culture to shorten the result.

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of dotnet/runtime@60108ba66e (2026-08-10). Data as JSON: /api/errors/47ff0262c69377d5. Report an issue: GitHub.

Appendix: 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 60108ba66e)