dotnet/aspnetcore · error · Error
Invalid JS call result type
Error message
Invalid JS call result type '${resultType}'. What it means
Thrown by createJSCallResult() when the resultType passed from .NET does not match any JSCallResultType enum case (Default=0, JSObjectReference=1, JSStreamReference=2, JSVoidResult=3). This is a defensive default branch; the value is supplied by the .NET runtime when invoking JS, so an unknown value means a version/protocol mismatch between the JS library and the .NET runtime.
Solutions
- Hard-refresh / clear cached Microsoft.JSInterop.js assets so the version matches the runtime.
- Ensure the npm @microsoft/dotnet-js-interop package version aligns with the SDK version.
- If hosting a custom dispatcher, only emit result type codes 0-3.
Example fix
// before (stale cached asset) // browser serves old Microsoft.JSInterop.js with new runtime -> unknown resultType // after // clear cache / cache-bust the JS asset so it matches the runtime version // e.g. append a version hash to the script src in index.html
Defensive patterns
Strategy: validation
Validate before calling
// Ensure the served JS interop asset matches the runtime version.
// <script src="_framework/blazor.webassembly.js?v={CACHE_BUSTER}"></script>
// and verify window.DotNet.JSCallResultType has the expected enum members. Type guard
function isKnownResultType(t) { return t === 0 || t === 1 || t === 2 || t === 3; } Try / catch
try { /* interop invoke */ } catch (e) { if (/Invalid JS call result type/.test(e.message)) { console.error('JS interop asset/runtime version mismatch. Clear cached assets and reload.'); } throw e; } Prevention
- Cache-bust or version the Microsoft.JSInterop.js / Blazor boot assets.
- Keep the @microsoft/dotnet-js-interop npm package version equal to the SDK version.
- Custom dispatchers must only emit result type codes 0-3.
When it happens
Trigger: .NET invokes a JS function with a result type code outside the known enum range (e.g. 4 or higher from a newer runtime loaded against an older JS asset). The switch in createJSCallResult falls through to default and throws.
Common situations: JS interop static asset cached (stale) in the browser while the .NET runtime was upgraded to a version using a new result type; mismatched npm package version; custom host emitting an invalid result type code.
Related errors
- Byte array index ' ' does not exist.
- Cannot create a JSObjectReference from the value
- Cannot create a JSStreamReference from the value
- Cannot create a JSStreamReference from the value
- Invalid headers.
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/8bef133e27e56f59.
Report an issue: GitHub.
Appendix: source
Thrown at src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts:805
this.streamPromise = new Promise((resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
});
}
}
function createJSCallResult(returnValue: any, resultType: JSCallResultType) {
switch (resultType) {
case JSCallResultType.Default:
return returnValue;
case JSCallResultType.JSObjectReference:
return createJSObjectReference(returnValue);
case JSCallResultType.JSStreamReference:
return createJSStreamReference(returnValue);
case JSCallResultType.JSVoidResult:
return null;
default:
throw new Error(`Invalid JS call result type '${resultType}'.`);
}
}
let nextByteArrayIndex = 0;
function stringifyArgs(callDispatcher: CallDispatcher, args: any[] | null) {
nextByteArrayIndex = 0;
currentCallDispatcher = callDispatcher;
const result = JSON.stringify(args, argReplacer);
currentCallDispatcher = undefined;
return result;
}
function getCaptureIdFromElement(element: Element): string | null {
for (let i = 0; i < element.attributes.length; i++) {
const attr = element.attributes[i];
if (attr.name.startsWith("_bl_")) {
return attr.name.substring(4);
}View on GitHub (pinned to 3600ca084e)