{"record":{"id":"5a98b6186140799a","repo":"dotnet/runtime","slug":"failed-to-load-resource-asset-name-from-as","errorCode":null,"errorMessage":"Failed to load resource '${asset.name}' from '${asset.resolvedUrl}': ${message}","messagePattern":"Failed to load resource '(.+?)' from '(.+?)': (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/native/libs/Common/JavaScript/loader/assets.ts","lineNumber":356,"sourceCode":"        }\n        assetInternal.behavior = \"symbols\";\n        assetInternal.isOptional = assetInternal.isOptional || loaderConfig.ignorePdbLoadErrors;\n        tableText = await fetchText(assetInternal);\n    } finally {\n        onDownloadedAsset(assetInternal);\n    }\n    dotnetDiagnosticsExports.installNativeSymbols(tableText || \"\");\n}\n\nasync function fetchBytes(asset: AssetEntryInternal): Promise<Uint8Array | null> {\n    dotnetAssert.check(asset && asset.resolvedUrl, \"Bad asset.resolvedUrl\");\n    let response: Response;\n    try {\n        response = await loadResource(asset);\n    } catch (err: any) {\n        // Strip .silent flag from download errors so they are properly reported via exit listeners\n        const message = err instanceof Error ? err.message : String(err);\n        throw new Error(`Failed to load resource '${asset.name}' from '${asset.resolvedUrl}': ${message}`, { cause: err });\n    }\n    if (!response.ok) {\n        if (asset.isOptional) {\n            dotnetLogger.warn(`Optional resource '${asset.name}' failed to load from '${asset.resolvedUrl}'. HTTP status: ${response.status} ${response.statusText}`);\n            return null;\n        }\n        throw new Error(`Failed to load resource '${asset.name}' from '${asset.resolvedUrl}'. HTTP status: ${response.status} ${response.statusText}`);\n    }\n    const buffer = await (asset.buffer || response.arrayBuffer());\n    return new Uint8Array(buffer);\n}\n\nasync function fetchText(asset: AssetEntryInternal): Promise<string | null> {\n    dotnetAssert.check(asset && asset.resolvedUrl, \"Bad asset.resolvedUrl\");\n    let response: Response;\n    try {\n        response = await loadResource(asset);\n    } catch (err: any) {","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/native/libs/Common/JavaScript/loader/assets.ts#L338-L374","documentation":"fetchBytes (loader/assets.ts) wraps loadResource(asset) in try/catch. If the underlying fetch/throttle/retry promise rejects (network error, DNS, CORS, abort), it is re-thrown with the asset name, resolvedUrl, and original message as cause. This covers byte resources: assemblies, PDBs, ICU, vfs files.","triggerScenarios":"A fetch() for a binary asset threw — network down, DNS failure, CORS rejection, integrity mismatch (SRI), TLS error, or an explicit AbortController abort. The error originates before any HTTP status is available.","commonSituations":"Misconfigured CORS headers on the server; integrity hash mismatch after redeploying changed files; offline/loss of connectivity during load; self-hosted assets served from a different origin without CORS; certificate/TLS issues.","solutions":["Open resolvedUrl in a browser / curl -v to see the underlying network error.","Fix CORS: serve assets with Access-Control-Allow-Origin matching the page origin, and ensure no-cache mode is permitted.","If hash changed after redeploy, clear browser cache and republish so integrity hashes in the boot config match the files.","Set loaderConfig.disableIntegrityCheck = true only temporarily to isolate SRI mismatch, then fix the root cause."],"exampleFix":"// before: assets on different origin, no CORS headers\napp.UseStaticFiles(); // serves from https://cdn.example.com without CORS\n\n// after: enable CORS for the wasm assets\napp.UseCors(b => b.WithOrigins(\"https://app.example.com\")\n               .WithMethods(\"GET\").AllowCredentials());","handlingStrategy":"retry","validationCode":"// Pre-flight: probe the asset URL is reachable\nconst ok = await fetch(asset.resolvedUrl, { method: 'HEAD' }).then(r => r.ok).catch(() => false);\nif (!ok) console.warn('Asset unreachable before load:', asset.resolvedUrl);","typeGuard":null,"tryCatchPattern":"try {\n  await runtime.fetchAsset(asset);\n} catch (err) {\n  if (/Failed to load resource/.test(err.message) && err.cause) {\n    // inspect err.cause for CORS/DNS/SRI; retry with backoff or report\n  } else throw err;\n}","preventionTips":["Serve assets with correct CORS headers from day one.","Keep integrity hashes in sync with deployed files (republish on every change).","Test loads from the production origin, not just localhost."],"tags":["network","fetch","assets","cors","integrity"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}