dotnet/aspnetcore · error · Error
Cannot create a JSStreamReference from the value
Error message
Cannot create a JSStreamReference from the value '${streamReference}' as it doesn't have a byteLength. What it means
Thrown by DotNet.createJSStreamReference() when the supplied value is a typed-array-like object (its .buffer is an ArrayBuffer) but its byteLength property is undefined. byteLength is required to tell .NET the stream's size up front.
Solutions
- Use a standard typed array (Uint8Array, Int32Array) which always carries byteLength.
- If wrapping custom data, construct a Uint8Array copy: new Uint8Array(yourBytes).
- Use a Blob if you only have raw bytes: new Blob([data]).
Example fix
// before
const ref = createJSStreamReference({ buffer: someArrayBuffer }); // no byteLength
// after
const ref = createJSStreamReference(new Uint8Array(someArrayBuffer)); Defensive patterns
Strategy: type-guard
Validate before calling
function hasByteLength(v) { return v != null && typeof v.byteLength === 'number'; }
if (v.buffer instanceof ArrayBuffer && !hasByteLength(v)) { throw new TypeError('Typed array missing byteLength'); } Type guard
function isTypedArrayWithByteLength(v: unknown): v is ArrayBufferView { return v != null && (v as any).buffer instanceof ArrayBuffer && typeof (v as any).byteLength === 'number'; } Try / catch
try { return DotNet.createJSStreamReference(value); } catch (e) { throw new Error('Pass a standard typed array or Blob for stream references.', { cause: e }); } Prevention
- Always pass standard typed arrays (Uint8Array, Int32Array) which guarantee byteLength.
- Avoid polyfills or wrappers that strip byteLength from ArrayBufferView objects.
- Prefer Blob for opaque byte payloads.
When it happens
Trigger: Passing a DataView or typed array whose byteLength has been deleted, or a custom ArrayBufferView-shaped object missing byteLength. Normal Uint8Array/Int32Array/etc. always have byteLength, so this only fires with malformed or polyfilled typed arrays.
Common situations: Using a mock or polyfill that doesn't fully implement the TypedArray spec; passing a hand-rolled object that quacks like an ArrayBufferView but omits byteLength; an older transpiler/runtime stripping the property.
Related errors
- Supplied value is not a typed array or blob.
- Cannot create a JSStreamReference from the value
- Byte array index ' ' does not exist.
- Cannot create a JSObjectReference from the value
- Invalid JS call result type
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/cb78c7f74abc13bf.
Report an issue: GitHub.
Appendix: source
Thrown at src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts:203
*
* @param streamReference The ArrayBufferView or Blob used to create the JavaScript stream reference.
* @returns The JavaScript data reference (this will be the same instance as the given object).
* @throws Error if the given value is not an Object or doesn't have a valid byteLength.
*/
export function createJSStreamReference(streamReference: ArrayBuffer | ArrayBufferView | Blob | any): any {
let length = -1;
// If we're given a raw Array Buffer, we interpret it as a `Uint8Array` as
// ArrayBuffers' aren't directly readable.
if (streamReference instanceof ArrayBuffer) {
streamReference = new Uint8Array(streamReference);
}
if (streamReference instanceof Blob) {
length = streamReference.size;
} 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}'.`);
}
View on GitHub (pinned to 3600ca084e)