{"record":{"id":"cb78c7f74abc13bf","repo":"dotnet/aspnetcore","slug":"cannot-create-a-jsstreamreference-from-the-value","errorCode":null,"errorMessage":"Cannot create a JSStreamReference from the value '${streamReference}' as it doesn't have a byteLength.","messagePattern":"Cannot create a JSStreamReference from the value '(.+?)' as it doesn't have a byteLength\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts","lineNumber":203,"sourceCode":"   *\n   * @param streamReference The ArrayBufferView or Blob used to create the JavaScript stream reference.\n   * @returns The JavaScript data reference (this will be the same instance as the given object).\n   * @throws Error if the given value is not an Object or doesn't have a valid byteLength.\n   */\n  export function createJSStreamReference(streamReference: ArrayBuffer | ArrayBufferView | Blob | any): any {\n      let length = -1;\n\n      // If we're given a raw Array Buffer, we interpret it as a `Uint8Array` as\n      // ArrayBuffers' aren't directly readable.\n      if (streamReference instanceof ArrayBuffer) {\n          streamReference = new Uint8Array(streamReference);\n      }\n\n      if (streamReference instanceof Blob) {\n          length = streamReference.size;\n      } else if (streamReference.buffer instanceof ArrayBuffer) {\n          if (streamReference.byteLength === undefined) {\n              throw new Error(`Cannot create a JSStreamReference from the value '${streamReference}' as it doesn't have a byteLength.`);\n          }\n\n          length = streamReference.byteLength;\n      } else {\n          throw new Error(\"Supplied value is not a typed array or blob.\");\n      }\n\n      const result: any = {\n          [jsStreamReferenceLengthKey]: length\n      };\n\n      try {\n          const jsObjectReference = createJSObjectReference(streamReference);\n          result[jsObjectIdKey] = jsObjectReference[jsObjectIdKey];\n      } catch (error) {\n          throw new Error(`Cannot create a JSStreamReference from the value '${streamReference}'.`);\n      }\n","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts#L185-L221","documentation":"Thrown by createJSStreamReference() in Microsoft.JSInterop.ts (line 203) when the supplied value is a typed-array-like object (it has streamReference.buffer instanceof ArrayBuffer) but lacks a byteLength property. The stream reference needs byteLength to tell .NET how many bytes to pull; without it the transfer cannot be sized, so the function refuses.","triggerScenarios":"Calling createJSStreamReference with an object whose [[Prototype]] gives it a buffer but on which byteLength is undefined — e.g., a custom wrapper around an ArrayBufferView, or a partially-constructed DataView/typed array before its byteLength is set.","commonSituations":"Passing a custom Buffer-like object instead of a real typed array (Uint8Array, Int32Array, etc.) or Blob. Object created via Object.create(Uint8Array.prototype) without setting byteLength. A polyfilled/shimmed typed array missing the property. Proxy-wrapped typed arrays that do not expose byteLength.","solutions":["Pass a real typed array (e.g., new Uint8Array(...)) or a Blob — these always carry byteLength/size.","If wrapping data, expose a byteLength getter that returns the underlying view's length.","Copy your custom buffer into a Uint8Array before creating the stream reference.","Avoid Proxy/wrapper layers around typed arrays passed to interop."],"exampleFix":"// before\nconst fake = Object.assign(Object.create(Uint8Array.prototype), { buffer: someBuffer });\nDotNet.createJSStreamReference(fake); // throws — no byteLength\n\n// after\nconst view = new Uint8Array(someBuffer);\nDotNet.createJSStreamReference(view);","handlingStrategy":"type-guard","validationCode":"function hasByteLength(v: any): boolean {\n  return v && v.buffer instanceof ArrayBuffer && typeof v.byteLength === 'number';\n}","typeGuard":"function isTypedArrayLike(v: any): v is ArrayBufferView {\n  return v && v.buffer instanceof ArrayBuffer && typeof v.byteLength === 'number';\n}","tryCatchPattern":null,"preventionTips":["Pass real typed arrays (Uint8Array, etc.) or Blobs.","Expose byteLength on custom wrappers.","Copy exotic buffers into a Uint8Array before streaming.","Avoid Proxies around typed arrays passed to interop."],"tags":["jsinterop","blazor","interop","stream","typed-array","typescript"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}