{"record":{"id":"a162b0a236920ce6","repo":"dotnet/aspnetcore","slug":"supplied-value-is-not-a-typed-array-or-blob","errorCode":null,"errorMessage":"Supplied value is not a typed array or blob.","messagePattern":"Supplied value is not a typed array or blob\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts","lineNumber":208,"sourceCode":"  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\n      return result;\n  }\n\n  /**\n   * Disposes the given JavaScript object reference.","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts#L190-L226","documentation":"Thrown by createJSStreamReference() in Microsoft.JSInterop.ts (line 208) when the supplied value is neither a Blob nor an object whose .buffer is an ArrayBuffer. The stream reference mechanism only knows how to size and transfer typed-array-backed data or Blobs; anything else (plain objects, primitives, ReadableStream, Response bodies, etc.) falls into the else branch and throws 'Supplied value is not a typed array or blob.'","triggerScenarios":"Calling createJSStreamReference with a value that is not a Blob and not an ArrayBufferView — e.g., a ReadableStream, a string, a plain object, a fetch Response, an ArrayBuffer (note: raw ArrayBuffers are auto-wrapped to Uint8Array earlier, so this branch is for other shapes), or a MediaSource.","commonSituations":"Trying to stream a fetch Response body (a ReadableStream) directly instead of buffering it into a Blob/Uint8Array. Passing a Node-style Buffer in an environment without the Buffer→Uint8Array compatibility. Passing a string and expecting streaming semantics. Handing a non-typed custom data structure.","solutions":["Materialize the data into a Uint8Array (e.g., await response.arrayBuffer() then new Uint8Array(...)) or a Blob before creating the stream reference.","For ReadableStream bodies, read all chunks into a Uint8Array first, or use response.blob().","Confirm the value is one of: ArrayBuffer (auto-wrapped), ArrayBufferView (Uint8Array etc.), or Blob.","Avoid passing Response/Request objects directly; extract their body data."],"exampleFix":"// before\nconst resp = await fetch('/data');\nDotNet.createJSStreamReference(resp.body); // ReadableStream → throws\n\n// after\nconst buf = await resp.arrayBuffer();\nDotNet.createJSStreamReference(new Uint8Array(buf));","handlingStrategy":"type-guard","validationCode":"function isStreamable(v: any): boolean {\n  return v instanceof Blob || v instanceof ArrayBuffer || (v && v.buffer instanceof ArrayBuffer);\n}","typeGuard":"function isStreamSource(v: unknown): v is Blob | ArrayBuffer | ArrayBufferView {\n  return v instanceof Blob || v instanceof ArrayBuffer || (typeof v === 'object' && v !== null && (v as any).buffer instanceof ArrayBuffer);\n}","tryCatchPattern":null,"preventionTips":["Materialize ReadableStream/Response bodies into Uint8Array or Blob first.","Confirm the value is ArrayBuffer, ArrayBufferView, or Blob.","Do not pass strings/Response/Request objects directly.","Use await response.arrayBuffer() before streaming."],"tags":["jsinterop","blazor","interop","stream","typed-array","blob","typescript"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}