{"record":{"id":"966c7cf8b542928a","repo":"dotnet/runtime","slug":"failed-to-initialize-icu-data","errorCode":null,"errorMessage":"Failed to initialize ICU data","messagePattern":"Failed to initialize ICU data","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/native/libs/Common/JavaScript/host/assets.ts","lineNumber":125,"sourceCode":"    _ems_.HEAPU32[outSize as any >>> 2] = 0;\n    _ems_.HEAPU32[((outSize as any) + 4) >>> 2] = 0;\n    return false;\n}\n\nexport function loadIcuData(bytes: Uint8Array) {\n    const sp = _ems_.stackSave();\n    try {\n        const ptrPtr = _ems_.stackAlloc(sizeOfPtr);\n        if (_ems_._posix_memalign(ptrPtr as any, 16, bytes.length)) {\n            throw new Error(\"posix_memalign failed for ICU data\");\n        }\n\n        const ptr = _ems_.HEAPU32[ptrPtr as any >>> 2];\n        _ems_.HEAPU8.set(bytes, ptr >>> 0);\n\n        const result = _ems_._wasm_load_icu_data(ptr as unknown as VoidPtr);\n        if (!result) {\n            throw new Error(\"Failed to initialize ICU data\");\n        }\n    } finally {\n        _ems_.stackRestore(sp);\n    }\n}\n\nexport function installVfsFile(bytes: Uint8Array, asset: VfsAsset) {\n    const virtualName: string = typeof (asset.virtualPath) === \"string\"\n        ? asset.virtualPath\n        : asset.name;\n    const lastSlash = virtualName.lastIndexOf(\"/\");\n    let parentDirectory = (lastSlash > 0)\n        ? virtualName.substring(0, lastSlash)\n        : browserVirtualAppBase;\n    let fileName = (lastSlash > 0)\n        ? virtualName.substring(lastSlash + 1)\n        : virtualName;\n    if (fileName.startsWith(\"/\")) {","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/native/libs/Common/JavaScript/host/assets.ts#L107-L143","documentation":"Thrown by loadIcuData after the native _wasm_load_icu_data call returns a falsy result. ICU data (icudt.dat) provides Unicode/globalization support (culture-aware casing, collation, calendars) to the .NET WASM runtime; without it, System.Globalization fails. The native loader rejected the bytes it was handed.","triggerScenarios":"Calling loadIcuData(bytes) where _wasm_load_icu_data returns 0: corrupted or truncated ICU .dat, an ICU version that does not match this runtime build, an empty/wrong byte buffer, or WASM linear-memory exhaustion at posix_memalign/load time.","commonSituations":"Custom host fetching icudt.dat from a stale/old URL; partial publish where icudt.dat is truncated on disk; serving the file pre-gzipped without Content-Encoding so the runtime reads compressed bytes; mixing invariant-globalization build with full-ICU data file; CDN serving a partial chunk.","solutions":["Verify the icudt.dat is the exact file shipped with this runtime build (match git hash / SDK version).","Check the byte length/hash of the fetched buffer against the expected asset manifest entry; re-fetch if mismatched.","Ensure the server is not double-compressing or mis-decompressing the .dat (Content-Encoding vs raw).","If globalization is not needed, switch the runtime to invariant globalization mode to skip ICU loading entirely."],"exampleFix":"// before: pointing loader at an old/standalone icudt.dat URL\nconfig.resources.icudt = [{ url: '/old/icudt.dat' }];\n// after: use the file from the matching runtime publish output\nconfig.resources.icudt = publishAssets.icudt; // same build as dotnet.native.wasm","handlingStrategy":"validation","validationCode":"// Validate the ICU bytes before loading\nimport { expectedIcuAssets } from './dotnet.runtime.config';\nconst expected = expectedIcuAssets.icudt?.[0];\nif (!bytes || bytes.byteLength === 0) throw new Error('ICU bytes empty');\nif (expected?.size && bytes.byteLength !== expected.size) {\n  throw new Error(`ICU size mismatch: got ${bytes.byteLength}, expected ${expected.size}`);\n}\nloadIcuData(bytes);","typeGuard":null,"tryCatchPattern":"try { loadIcuData(bytes); }\ncatch (e) {\n  if (/Failed to initialize ICU data/.test(String(e.message))) {\n    // surface a deployment hint: re-fetch the matching icudt.dat\n    throw new Error('ICU load failed; verify the icudt.dat matches this runtime build.', { cause: e });\n  }\n  throw e;\n}","preventionTips":["Always source icudt.dat from the same publish output as dotnet.native.wasm.","Prefer invariant globalization in CI/tests that do not need culture data to skip ICU loading.","Verify fetched asset length against the runtime config manifest before handing bytes to loadIcuData."],"tags":["icu","globalization","wasm","initialization","assets"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}