dotnet/runtime · critical · Error

Failed to initialize ICU data

Error message

Failed to initialize ICU data

What it means

Thrown by loadIcuData() (src/native/libs/Common/JavaScript/host/assets.ts:181) after the aligned buffer is allocated and copied. The buffer is handed to _wasm_load_icu_data; if that native function returns a falsy value the ICU engine rejected the data (parse failure, version mismatch, or wrong endianness), and the runtime cannot provide globalization.

Solutions

  1. Re-publish so the ICU shard matches the runtime's ICU version (do not mix SDK/runtime ICU artifacts).
  2. Verify the downloaded ICU asset is the real binary (check Content-Type and that it is not an HTML error page).
  3. Keep integrity hashes enabled so a corrupted ICU file is rejected before it reaches the loader.

Example fix

// before: integrity disabled, CDN served an HTML 404 page as icudt.dat
// config: { disableIntegrityCheck: true }

// after: keep integrity on and serve the correct binary
// config: { /* integrity enabled (default) */ }
Defensive patterns

Strategy: try-catch

Validate before calling

async function verifyIcuBytes(url: string): Promise<boolean> {
  const r = await fetch(url);
  const ct = r.headers.get('Content-Type') || '';
  return r.ok && ct !== 'text/html'; // not an error page
}

Try / catch

try {
  await dotnetBrowserHostExports.loadIcuData(bytes);
} catch (err) {
  if (/Failed to initialize ICU data/.test(String((err as Error).message))) {
    // ICU data version mismatch or corruption: redeploy matching ICU shard
  }
  throw err;
}

Prevention

When it happens

Trigger: The ICU bytes are allocated and copied into the heap, then _wasm_load_icu_data(ptr) is called. A zero/false return triggers the error at line 193.

Common situations: ICU data file from a different ICU major version than the runtime's native ICU; truncated or corrupted icudt download (e.g. a 200 HTML error page saved as the asset); integrity check disabled so a bad file was accepted.

Related errors


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

Appendix: source

Thrown at src/native/libs/Common/JavaScript/host/assets.ts:194

    _ems_.HEAPU32[outSize as any >>> 2] = 0;
    _ems_.HEAPU32[((outSize as any) + 4) >>> 2] = 0;
    return false;
}

export function loadIcuData(bytes: Uint8Array) {
    const sp = _ems_.stackSave();
    try {
        const ptrPtr = _ems_.stackAlloc(sizeOfPtr);
        if (_ems_._posix_memalign(ptrPtr as any, 16, bytes.length)) {
            throw new Error("posix_memalign failed for ICU data");
        }

        const ptr = _ems_.HEAPU32[ptrPtr as any >>> 2];
        _ems_.HEAPU8.set(bytes, ptr >>> 0);

        const result = _ems_._wasm_load_icu_data(ptr as unknown as VoidPtr);
        if (!result) {
            throw new Error("Failed to initialize ICU data");
        }
    } finally {
        _ems_.stackRestore(sp);
    }
}

export function installVfsFile(bytes: Uint8Array, asset: VfsAsset) {
    const virtualName: string = typeof (asset.virtualPath) === "string"
        ? asset.virtualPath
        : asset.name;
    const lastSlash = virtualName.lastIndexOf("/");
    let parentDirectory = (lastSlash > 0)
        ? virtualName.substring(0, lastSlash)
        : browserVirtualAppBase;
    let fileName = (lastSlash > 0)
        ? virtualName.substring(lastSlash + 1)
        : virtualName;
    if (fileName.startsWith("/")) {

View on GitHub (pinned to 60108ba66e)