{"record":{"id":"f18c20cc5f081072","repo":"dotnet/aspnetcore","slug":"cannot-create-a-jsstreamreference-from-the-value-f18c20","errorCode":null,"errorMessage":"Cannot create a JSStreamReference from the value '${streamReference}'.","messagePattern":"Cannot create a JSStreamReference from the value '(.+?)'\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts","lineNumber":219,"sourceCode":"      } 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.\n   *\n   * @param jsObjectReference The JavaScript Object reference.\n   */\n  export function disposeJSObjectReference(jsObjectReference: any): void {\n      const id = jsObjectReference && jsObjectReference[jsObjectIdKey];\n\n      if (typeof id === \"number\" && id !== -1) {\n          disposeJSObjectReferenceById(id);\n      }\n  }\n","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts#L201-L237","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst blob = new Proxy(new Blob([data]), handler); // wraps weirdly\nDotNet.createJSStreamReference(blob);\n\n// after\nconst bytes = new Uint8Array(await blob.arrayBuffer());\nDotNet.createJSStreamReference(bytes);","handlingStrategy":"try-catch","validationCode":"function isPlainStreamable(v: any): boolean {\n  return (v instanceof Blob && v.constructor === Blob) || (v instanceof Uint8Array && v.constructor === Uint8Array);\n}","typeGuard":null,"tryCatchPattern":"try {\n  DotNet.createJSStreamReference(value);\n} catch (e) {\n  // fall back: materialize into a plain Uint8Array\n  const bytes = value instanceof Blob ? new Uint8Array(await value.arrayBuffer()) : new Uint8Array(value);\n  DotNet.createJSStreamReference(bytes);\n}","preventionTips":["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."],"tags":["jsinterop","blazor","interop","stream","typescript","edge-case"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}