dotnet/aspnetcore · error · Error
Cannot create a JSStreamReference from the value
Error message
Cannot create a JSStreamReference from the value '${streamReference}'. What it means
Thrown by DotNet.createJSStreamReference() as a catch-all wrapper when the internal createJSObjectReference() call fails while building the stream reference. Since the stream code has already validated the value is a Blob or typed array, this fallback fires only if the value is somehow not an object/function after those checks (essentially unreachable in normal use).
Solutions
- Ensure the value passed is a genuine Blob or standard typed array instance, not a proxy or wrapper.
- Log the value's typeof and constructor before calling createJSStreamReference to diagnose.
- Reconstruct the data as a plain Uint8Array to bypass any proxying.
Example fix
// before
const ref = createJSStreamReference(new Proxy(new Uint8Array(8), {}));
// after
const ref = createJSStreamReference(new Uint8Array(8)); Defensive patterns
Strategy: try-catch
Validate before calling
function isPlainObjectOrTypedArray(v) { return v != null && (v instanceof Blob || v.buffer instanceof ArrayBuffer) && typeof v === 'object'; } Try / catch
try { return DotNet.createJSStreamReference(value); } catch (e) { throw new Error(`Stream reference creation failed for ${Object.prototype.toString.call(value)}.`, { cause: e }); } Prevention
- Avoid Proxy wrapping around typed arrays or Blobs passed to interop.
- Verify the value's constructor is the native Uint8Array/Blob before streaming.
- Rebuild data as a plain Uint8Array if creation unexpectedly fails.
When it happens
Trigger: The Blob/typed-array passed has been mutated or proxied such that createJSObjectReference's typeof check fails; a Symbol or other exotic non-object value slips through; defensive code path for unexpected inputs.
Common situations: Proxy-wrapped typed array whose typeof is not 'object'; a Blob polyfill that returns a non-object; extremely rare in practice — usually indicates a corrupted or non-standard runtime.
Related errors
- Cannot create a JSObjectReference from the value
- Cannot create a JSStreamReference from the value
- JS object instance with Id
- Supplied value is not a typed array or blob.
- Byte array index ' ' does not exist.
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/f18c20cc5f081072.
Report an issue: GitHub.
Appendix: source
Thrown at src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts:219
} else if (streamReference.buffer instanceof ArrayBuffer) {
if (streamReference.byteLength === undefined) {
throw new Error(`Cannot create a JSStreamReference from the value '${streamReference}' as it doesn't have a byteLength.`);
}
length = streamReference.byteLength;
} else {
throw new Error("Supplied value is not a typed array or blob.");
}
const result: any = {
[jsStreamReferenceLengthKey]: length
};
try {
const jsObjectReference = createJSObjectReference(streamReference);
result[jsObjectIdKey] = jsObjectReference[jsObjectIdKey];
} catch (error) {
throw new Error(`Cannot create a JSStreamReference from the value '${streamReference}'.`);
}
return result;
}
/**
* Disposes the given JavaScript object reference.
*
* @param jsObjectReference The JavaScript Object reference.
*/
export function disposeJSObjectReference(jsObjectReference: any): void {
const id = jsObjectReference && jsObjectReference[jsObjectIdKey];
if (typeof id === "number" && id !== -1) {
disposeJSObjectReferenceById(id);
}
}
View on GitHub (pinned to 3600ca084e)