{"record":{"id":"32b668194fbb158a","repo":"dotnet/aspnetcore","slug":"js-object-instance-with-id-targetinstanceid-doe","errorCode":null,"errorMessage":"JS object instance with ID ${targetInstanceId} does not exist (has it been disposed?).","messagePattern":"JS object instance with ID (.+?) does not exist \\(has it been disposed\\?\\)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts","lineNumber":578,"sourceCode":"      }\n  }\n\n  function formatError(error: Error | string): string {\n      if (error instanceof Error) {\n          return `${error.message}\\n${error.stack}`;\n      }\n\n      return error ? error.toString() : \"null\";\n  }\n\n  export function findJSFunction(identifier: string, targetInstanceId: number, callType?: JSCallType): Function {\n      const targetInstance = cachedJSObjectsById[targetInstanceId];\n\n      if (targetInstance) {\n          return targetInstance.resolveInvocationHandler(identifier, callType ?? JSCallType.FunctionCall);\n      }\n\n      throw new Error(`JS object instance with ID ${targetInstanceId} does not exist (has it been disposed?).`);\n  }\n\n  export function disposeJSObjectReferenceById(id: number) {\n      delete cachedJSObjectsById[id];\n  }\n\n  /**\n   * Traverses the object hierarchy to find an object member specified by the identifier.\n   *\n   * @param obj Root object to search in.\n   * @param identifier Complete identifier of the member to find, e.g. \"document.location.href\".\n   * @returns A tuple containing the immediate parent of the member and the member name.\n   */\n  export function findObjectMember(obj: any, identifier: string): [any, string] {\n      const keys = identifier.split(\".\");\n      let current = obj;\n\n      // First, we iterate over all but the last key. We throw error for missing intermediate keys.","sourceCodeStart":560,"sourceCodeEnd":596,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts#L560-L596","documentation":"Thrown by DotNet.findJSFunction() when no cached JSObject exists for the given targetInstanceId. Every JS interop call from .NET targets an instance by numeric ID (0 = window); if that ID was disposed or never registered, the call cannot resolve. The most common cause is using a JS object reference after it was disposed.","triggerScenarios":".NET calls a JS function on an IJSObjectReference that was already disposed (or whose underlying object was garbage-collected via disposeJSObjectReferenceById). Also when the ID is stale after a Blazor circuit reconnect or page refresh.","commonSituations":"Calling a method on a disposed IJSObjectReference; holding a JS object reference across a Blazor Server reconnect that lost the cache; calling dispose on a reference then using it again.","solutions":["Do not use an IJSObjectReference after calling Dispose on it.","After Blazor reconnect, re-acquire JS object references rather than reusing old ones.","Track disposal state on the .NET side and skip calls to disposed references."],"exampleFix":"// C# before\nawait jsRef.InvokeVoidAsync(\"doThing\");\nawait jsRef.DisposeAsync();\nawait jsRef.InvokeVoidAsync(\"doThing\"); // throws in JS\n\n// after\nawait jsRef.InvokeVoidAsync(\"doThing\");\nawait jsRef.DisposeAsync();\njsRef = null; // null and re-acquire if needed","handlingStrategy":"validation","validationCode":"// .NET: null-check and dispose-track IJSObjectReference before invoking.\nif (jsRef is null) { return; }\nawait jsRef.InvokeVoidAsync(\"doThing\");","typeGuard":null,"tryCatchPattern":"try { await jsRef.InvokeVoidAsync(\"doThing\"); } catch (JSException e) when (e.Message.Contains(\"does not exist\")) { jsRef = null; /* re-acquire or give up */ }","preventionTips":["Set IJSObjectReference to null immediately after DisposeAsync.","Do not share JS object references across Blazor circuit reconnects.","Track disposal state on the .NET side to avoid using stale handles."],"tags":["js-interop","blazor","object-reference","disposed","lifecycle"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}