dotnet/aspnetcore · error

Supplied value is not a typed array or blob.

Error message

Supplied value is not a typed array or blob.

What it means

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.'

Source

Thrown at src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts:208

  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}'.`);
      }

      return result;
  }

  /**
   * Disposes the given JavaScript object reference.

View on GitHub (pinned to 294cab2f9b)

Solutions

  1. Materialize the data into a Uint8Array (e.g., await response.arrayBuffer() then new Uint8Array(...)) or a Blob before creating the stream reference.
  2. For ReadableStream bodies, read all chunks into a Uint8Array first, or use response.blob().
  3. Confirm the value is one of: ArrayBuffer (auto-wrapped), ArrayBufferView (Uint8Array etc.), or Blob.
  4. Avoid passing Response/Request objects directly; extract their body data.

Example fix

// before
const resp = await fetch('/data');
DotNet.createJSStreamReference(resp.body); // ReadableStream → throws

// after
const buf = await resp.arrayBuffer();
DotNet.createJSStreamReference(new Uint8Array(buf));
Defensive patterns

Strategy: type-guard

Validate before calling

function isStreamable(v: any): boolean {
  return v instanceof Blob || v instanceof ArrayBuffer || (v && v.buffer instanceof ArrayBuffer);
}

Type guard

function isStreamSource(v: unknown): v is Blob | ArrayBuffer | ArrayBufferView {
  return v instanceof Blob || v instanceof ArrayBuffer || (typeof v === 'object' && v !== null && (v as any).buffer instanceof ArrayBuffer);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06). Data as JSON: /api/errors/a162b0a236920ce6. Report an issue: GitHub.