{"record":{"id":"c9d8f9bdffb56510","repo":"dotnet/runtime","slug":"failed-to-load-webcil-module-virtualpath-htt","errorCode":null,"errorMessage":"Failed to load Webcil module '${virtualPath}'. HTTP status: ${(res as Response)?.status} ${(res as Response)?.statusText}","messagePattern":"Failed to load Webcil module '(.+?)'\\. HTTP status: (.+?) (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/native/libs/Common/JavaScript/host/assets.ts","lineNumber":86,"sourceCode":"            instance = instantiated.instance;\n        } else {\n            const data = await res.arrayBuffer();\n            const instantiated = await WebAssembly.instantiate(data, imports);\n            instance = instantiated.instance;\n        }\n        finishWebcilInstance(instance, payloadPtr, payloadSize, tableEntries, virtualPath);\n    } catch (err) {\n        // Instantiation failed after the payload buffer was allocated; free it to avoid leaking\n        // unmanaged memory. (A grown R2R table cannot be shrunk back, but a failed R2R instantiate is fatal.)\n        _ems_._free(payloadPtr as any);\n        throw err;\n    }\n}\n\nasync function checkWebcilResponse(webcilPromise: Promise<Response>, virtualPath: string): Promise<Response> {\n    const res = await webcilPromise;\n    if (!res || res.ok === false) {\n        throw new Error(`Failed to load Webcil module '${virtualPath}'. HTTP status: ${(res as Response)?.status} ${(res as Response)?.statusText}`);\n    }\n    return res;\n}\n\n// Allocates a 16-byte-aligned buffer for the Webcil payload. The pointer is heap memory that\n// outlives the stack frame, so it can be passed as the imageBase import.\nfunction allocWebcilPayload(payloadSize: number): number {\n    const sp = _ems_.stackSave();\n    try {\n        const ptrPtr = _ems_.stackAlloc(sizeOfPtr);\n        if (_ems_._posix_memalign(ptrPtr as any, 16, payloadSize)) {\n            throw new Error(\"posix_memalign failed for Webcil payload\");\n        }\n        return _ems_.HEAPU32[ptrPtr as any >>> 2];\n    } finally {\n        _ems_.stackRestore(sp);\n    }\n}","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/native/libs/Common/JavaScript/host/assets.ts#L68-L104","documentation":"Thrown by checkWebcilResponse() (src/native/libs/Common/JavaScript/host/assets.ts:83) when the awaited Response for a Webcil asset is falsy or res.ok === false. instantiateWebcilModule awaits this check before allocating the payload buffer, so a failed fetch surfaces as an HTTP status rather than a cryptic WebAssembly error.","triggerScenarios":"fetchWebcil() resolves the webcilPromise via loadResource, then instantiateWebcilModule calls checkWebcilResponse. A 404 for the .wasm file, a CDN error (5xx), a CORS block producing an opaque response, or a custom loadBootResourceCallback returning a failed Response all trigger this.","commonSituations":"Asset not published/deployed (404); wrong application base / CDN path; CORS misconfiguration returning an error response; integrity check failure promoted to a non-OK response; a custom loadBootResourceCallback returning the wrong URL.","solutions":["Open the failing virtualPath URL directly in the browser/network tab and confirm it returns 200 with Content-Type application/wasm.","Verify the deployed wwwroot/_framework contains the .wasm file and the application base / CDN prefix matches.","If using a custom loadBootResourceCallback, return a Response that resolves ok:true (and the correct URL).","Fix CORS so the response is usable (correct headers, no opaque no-cors response)."],"exampleFix":"// before\nloadBootResource: (type, name, uri) => uri.replace('/cdn/', '/wrong/') // -> 404\n\n// after\nloadBootResource: (type, name, uri) => uri // return a resolvable URL","handlingStrategy":"retry","validationCode":"async function probeWebcil(url: string): Promise<boolean> {\n  const r = await fetch(url, { method: 'HEAD' });\n  return r.ok;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await instantiateWebcilModule(webcilPromise, memory, virtualPath, tableSize, payloadSize);\n} catch (err) {\n  if (/Failed to load Webcil module/.test(String((err as Error).message))) {\n    // inspect the HTTP status embedded in the message; redeploy the asset or fix CORS\n  }\n  throw err;\n}","preventionTips":["Deploy every webcil .wasm asset under _framework/ and verify with a HEAD request.","Configure CORS so responses are usable (not opaque).","Forward payloadSize/tableSize through any custom loadBootResourceCallback."],"tags":["network","webcil","http","deployment"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}