{"record":{"id":"f0b5e4b519e9cb05","repo":"dotnet/aspnetcore","slug":"byte-array-index-index-does-not-exist","errorCode":null,"errorMessage":"Byte array index '${index}' does not exist.","messagePattern":"Byte array index '(.+?)' does not exist\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts","lineNumber":744,"sourceCode":"\n  attachReviver(function reviveReference(key: any, value: any) {\n      if (value && typeof value === \"object\") {\n          if (value.hasOwnProperty(dotNetObjectRefKey)) {\n              return new DotNetObject(value[dotNetObjectRefKey], currentCallDispatcher!);\n          } else if (value.hasOwnProperty(jsObjectIdKey)) {\n              const id = value[jsObjectIdKey];\n              const jsObject = cachedJSObjectsById[id];\n\n              if (jsObject) {\n                  return jsObject.getWrappedObject();\n              }\n\n              throw new Error(`JS object instance with Id '${id}' does not exist. It may have been disposed.`);\n          } else if (value.hasOwnProperty(byteArrayRefKey)) {\n              const index = value[byteArrayRefKey];\n              const byteArray = currentCallDispatcher!.processByteArray(index);\n              if (byteArray === undefined) {\n                  throw new Error(`Byte array index '${index}' does not exist.`);\n              }\n              return byteArray;\n          } else if (value.hasOwnProperty(dotNetStreamRefKey)) {\n              const streamId = value[dotNetStreamRefKey];\n              const streamPromise = currentCallDispatcher!.getDotNetStreamPromise(streamId);\n              return new DotNetStream(streamPromise);\n          }\n      }\n\n      // Unrecognized - let another reviver handle it\n      return value;\n  });\n\n  class DotNetStream {\n      // eslint-disable-next-line no-empty-function\n      constructor(private readonly _streamPromise: Promise<ReadableStream>) {\n      }\n","sourceCodeStart":726,"sourceCodeEnd":762,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts#L726-L762","documentation":"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.","triggerScenarios":".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.","commonSituations":"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.","solutions":["Ensure the Microsoft.JSInterop.JS asset version matches the .NET runtime.","After reconnect, re-request byte arrays rather than reusing old references.","If you see null instead of this error, suspect the === undefined vs null mismatch and report it as a library bug."],"exampleFix":"// No user-facing fix; this guards an internal protocol contract.\n// Ensure version alignment and avoid reusing byte-array refs across reconnects.\n// before: stale ref after reconnect\nawait JS.InvokeAsync<byte[]>(\"getData\", oldByteRef);\n// after: re-request fresh data\nvar bytes = await JS.InvokeAsync<byte[]>(\"getData\");","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["Keep the JS interop asset version aligned with the .NET runtime.","Re-request byte arrays after a Blazor reconnect instead of reusing old references.","If you observe null instead of this error, suspect the undefined-vs-null check bug and report it."],"tags":["js-interop","blazor","byte-array","serialization","reviver","protocol"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}