{"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":"Error","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/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts#L201-L237","documentation":"Thrown by DotNet.createJSStreamReference() as a catch-all wrapper when the internal createJSObjectReference() call fails while building the stream reference. Since the stream code has already validated the value is a Blob or typed array, this fallback fires only if the value is somehow not an object/function after those checks (essentially unreachable in normal use).","triggerScenarios":"The Blob/typed-array passed has been mutated or proxied such that createJSObjectReference's typeof check fails; a Symbol or other exotic non-object value slips through; defensive code path for unexpected inputs.","commonSituations":"Proxy-wrapped typed array whose typeof is not 'object'; a Blob polyfill that returns a non-object; extremely rare in practice — usually indicates a corrupted or non-standard runtime.","solutions":["Ensure the value passed is a genuine Blob or standard typed array instance, not a proxy or wrapper.","Log the value's typeof and constructor before calling createJSStreamReference to diagnose.","Reconstruct the data as a plain Uint8Array to bypass any proxying."],"exampleFix":"// before\nconst ref = createJSStreamReference(new Proxy(new Uint8Array(8), {}));\n\n// after\nconst ref = createJSStreamReference(new Uint8Array(8));","handlingStrategy":"try-catch","validationCode":"function isPlainObjectOrTypedArray(v) { return v != null && (v instanceof Blob || v.buffer instanceof ArrayBuffer) && typeof v === 'object'; }","typeGuard":null,"tryCatchPattern":"try { return DotNet.createJSStreamReference(value); } catch (e) { throw new Error(`Stream reference creation failed for ${Object.prototype.toString.call(value)}.`, { cause: e }); }","preventionTips":["Avoid Proxy wrapping around typed arrays or Blobs passed to interop.","Verify the value's constructor is the native Uint8Array/Blob before streaming.","Rebuild data as a plain Uint8Array if creation unexpectedly fails."],"tags":["js-interop","blazor","stream","object-reference","serialization"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}