dotnet/aspnetcore · error
Cannot create a JSStreamReference from the value '${streamRe
Error message
Cannot create a JSStreamReference from the value '${streamReference}'. What it means
Thrown by createJSStreamReference() in Microsoft.JSInterop.ts (line 219) as a catch-all when the inner createJSObjectReference(streamReference) call throws. After successfully computing the stream length, the function wraps the underlying data as a JS object reference so .NET can pull bytes; if that wrapping fails (the data is not a wrappable object), this generic message wraps the original error.
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 294cab2f9b)
Solutions
- Pass a plain, unmodified Blob or Uint8Array rather than a subclass/Proxy.
- Copy exotic data into a standard Uint8Array before streaming.
- Inspect the inner error (the thrown Error is generic; check the console for the underlying createJSObjectReference reason) and fix the root cause per error 74.
- Avoid reassigning streamReference between the length check and the wrap call.
Example fix
// before const blob = new Proxy(new Blob([data]), handler); // wraps weirdly DotNet.createJSStreamReference(blob); // after const bytes = new Uint8Array(await blob.arrayBuffer()); DotNet.createJSStreamReference(bytes);
Defensive patterns
Strategy: try-catch
Validate before calling
function isPlainStreamable(v: any): boolean {
return (v instanceof Blob && v.constructor === Blob) || (v instanceof Uint8Array && v.constructor === Uint8Array);
} Try / catch
try {
DotNet.createJSStreamReference(value);
} catch (e) {
// fall back: materialize into a plain Uint8Array
const bytes = value instanceof Blob ? new Uint8Array(await value.arrayBuffer()) : new Uint8Array(value);
DotNet.createJSStreamReference(bytes);
} Prevention
- Pass plain, unmodified Blob/Uint8Array instances.
- Avoid Blob/typed-array subclasses and Proxies.
- Materialize exotic data into Uint8Array first.
- Inspect the underlying createJSObjectReference error when this fires.
When it happens
Trigger: streamReference passes the Blob/typed-array length checks but then createJSObjectReference rejects it — e.g., a Blob subclass whose constructor returns a primitive, or a Proxy that breaks instanceof/typeof checks. The length was computed but the object identity itself is not wrappable.
Common situations: Custom Blob/typed-array subclasses or Proxies that pass the length-detection branches but fail object-reference wrapping. Frozen/sealed objects with unusual prototypes. Edge cases where instanceof checks succeed at length-time but the value is later replaced. This is rare; usually error 75/76 fires first.
Related errors
- Cannot create a JSStreamReference from the value '${streamRe
- Supplied value is not a typed array or blob.
- Cannot create a JSObjectReference from the value '${jsObject
- No call dispatcher has been set.
- There are multiple .NET runtimes present, so a default dispa
AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06).
Data as JSON: /api/errors/f18c20cc5f081072.
Report an issue: GitHub.