{"record":{"id":"e4371d07faaea4c5","repo":"dotnet/runtime","slug":"failed-to-load-webassembly-module-http-status","errorCode":null,"errorMessage":"Failed to load WebAssembly module. HTTP status: ${res?.status} ${res?.statusText}","messagePattern":"Failed to load WebAssembly module\\. HTTP status: (.+?) (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"src/native/libs/Common/JavaScript/host/assets.ts","lineNumber":179,"sourceCode":"            const data = await res.arrayBuffer();\n            module = await WebAssembly.compile(data);\n            instance = await WebAssembly.instantiate(module, imports);\n        } else {\n            const instantiated = await WebAssembly.instantiateStreaming(wasmPromise, imports);\n            instance = instantiated.instance;\n            module = instantiated.module;\n        }\n        return { instance, module };\n    } catch (err) {\n        _ems_.dotnetApi.exit(1, err);\n        throw err;\n    }\n\n    async function checkResponseOk(wasmPromise: Promise<Response> | undefined): Promise<Response & { isStreamingOk?: boolean }> {\n        _ems_.dotnetAssert.check(wasmPromise, \"WASM binary promise was not initialized\");\n        const res = (await wasmPromise) as Response & { isStreamingOk?: boolean };\n        if (!res || res.ok === false) {\n            throw new Error(`Failed to load WebAssembly module. HTTP status: ${res?.status} ${res?.statusText}`);\n        }\n        res.isStreamingOk = typeof globalThis.Response === \"function\" && res instanceof globalThis.Response;\n        const contentType = res.headers && res.headers.get ? res.headers.get(\"Content-Type\") : undefined;\n        if (_ems_.ENVIRONMENT_IS_WEB && contentType !== \"application/wasm\") {\n            _ems_.dotnetLogger.warn(\"WebAssembly resource does not have the expected content type \\\"application/wasm\\\", so falling back to slower ArrayBuffer instantiation.\");\n            res.isStreamingOk = false;\n        }\n        return res;\n    }\n}\n","sourceCodeStart":161,"sourceCodeEnd":190,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/native/libs/Common/JavaScript/host/assets.ts#L161-L190","documentation":"Thrown inside instantiateWasm -> checkResponseOk when the fetch of the native dotnet.native.wasm binary resolves with ok === false. The HTTP status and statusText are included so a 404, 403, or 500 is distinguishable. This is the top-level WASM module fetch; failure aborts runtime startup.","triggerScenarios":"instantiateWasm(wasmPromise, imports) where the Response.status is >= 400: file missing (404), auth forbidden (401/403), server error (5xx), or a Response that is undefined/null.","commonSituations":"Wrong deploy path or base-href so _framework/_bin/dotnet.native.wasm 404s; reverse proxy/CDN stripping the asset; publish output missing the wasm (truncated deploy); CORS preflight rejection; dev server not serving the binary directory.","solutions":["Open the exact failing URL (status + statusText are in the message) in a browser/Network tab to confirm 404/403/500.","Verify the published _framework folder contains dotnet.native.wasm and the served path matches <base href>.","For 401/403, fix auth/CORS headers and CDN access rules for the wasm asset.","Ensure the host sends Content-Type: application/wasm so streaming instantiation works (avoids a slower fallback and some rejections)."],"exampleFix":"// before: misconfigured base href causes 404 on wasm\n<script src=\"/framework/dotnet.runtime.js\"></script>\n// after: base href + asset path match publish layout\n<base href=\"/app/\" />\n<script src=\"_framework/dotnet.runtime.js\"></script>","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await instantiateWasm(wasmPromise, imports);\n} catch (e) {\n  const m = /HTTP status: (\\d{3})/.exec(String(e.message));\n  const status = m ? +m[1] : 0;\n  if (status === 404) throw new Error('dotnet.native.wasm not found; check <base href> and publish output.', { cause: e });\n  if (status === 401 || status === 403) throw new Error('Auth/CORS blocked the wasm asset.', { cause: e });\n  throw e;\n}","preventionTips":["Publish with the standard MSBuild target so the wasm lands at the expected _framework path.","Keep <base href> consistent with the deployed route.","In dev, disable the browser cache so a corrected 404 is rechecked immediately.","Ensure the host serves .wasm with Content-Type: application/wasm and allows CORS GET."],"tags":["wasm","network","http","deployment","assets"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}