dotnet/aspnetcore · error · Error

Byte array index ' ' does not exist.

Error message

Byte array index '${index}' does not exist.

What it means

Thrown by the reviveReference JSON reviver when a __byte[] marker references a byte-array index that processByteArray() cannot resolve. Byte arrays sent from .NET to JS are stored in a per-dispatcher Map keyed by index; the reviver looks them up by that index. Note: as written, processByteArray returns null (not undefined) on a miss, while the guard checks === undefined — so the throw is effectively dead code and a miss would silently yield null. The intended meaning is a missing byte-array transfer.

Solutions

  1. Ensure the Microsoft.JSInterop.JS asset version matches the .NET runtime.
  2. After reconnect, re-request byte arrays rather than reusing old references.
  3. If you see null instead of this error, suspect the === undefined vs null mismatch and report it as a library bug.

Example fix

// No user-facing fix; this guards an internal protocol contract.
// Ensure version alignment and avoid reusing byte-array refs across reconnects.
// before: stale ref after reconnect
await JS.InvokeAsync<byte[]>("getData", oldByteRef);
// after: re-request fresh data
var bytes = await JS.InvokeAsync<byte[]>("getData");
Defensive patterns

Strategy: try-catch

Try / catch

try { /* reviver path that resolves byte arrays */ } catch (e) { if (/Byte array index/.test(e.message)) { console.error('Byte-array index missing — check runtime/JS asset version alignment.'); } throw e; }

Prevention

When it happens

Trigger: .NET sends a byte-array reference marker for an index that was never registered via receiveByteArray, or whose data was already consumed/deleted by an earlier revival. Indicates the byte-array transfer protocol is out of sync between .NET and JS.

Common situations: Version mismatch between runtime and JS interop asset; a reconnect or reload where the byte-array Map was cleared but .NET still references old indices; double-revival of the same marker.

Related errors


AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11). Data as JSON: /api/errors/f0b5e4b519e9cb05. Report an issue: GitHub.

Appendix: source

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

  attachReviver(function reviveReference(key: any, value: any) {
      if (value && typeof value === "object") {
          if (value.hasOwnProperty(dotNetObjectRefKey)) {
              return new DotNetObject(value[dotNetObjectRefKey], currentCallDispatcher!);
          } else if (value.hasOwnProperty(jsObjectIdKey)) {
              const id = value[jsObjectIdKey];
              const jsObject = cachedJSObjectsById[id];

              if (jsObject) {
                  return jsObject.getWrappedObject();
              }

              throw new Error(`JS object instance with Id '${id}' does not exist. It may have been disposed.`);
          } else if (value.hasOwnProperty(byteArrayRefKey)) {
              const index = value[byteArrayRefKey];
              const byteArray = currentCallDispatcher!.processByteArray(index);
              if (byteArray === undefined) {
                  throw new Error(`Byte array index '${index}' does not exist.`);
              }
              return byteArray;
          } else if (value.hasOwnProperty(dotNetStreamRefKey)) {
              const streamId = value[dotNetStreamRefKey];
              const streamPromise = currentCallDispatcher!.getDotNetStreamPromise(streamId);
              return new DotNetStream(streamPromise);
          }
      }

      // Unrecognized - let another reviver handle it
      return value;
  });

  class DotNetStream {
      // eslint-disable-next-line no-empty-function
      constructor(private readonly _streamPromise: Promise<ReadableStream>) {
      }

View on GitHub (pinned to 3600ca084e)