{"record":{"id":"249f71f05c9f3188","repo":"dotnet/aspnetcore","slug":"there-are-multiple-net-runtimes-present-so-a-def","errorCode":null,"errorMessage":"There are multiple .NET runtimes present, so a default dispatcher could not be resolved. Use DotNetObject to invoke .NET instance methods.","messagePattern":"There are multiple \\.NET runtimes present, so a default dispatcher could not be resolved\\. Use DotNetObject to invoke \\.NET instance methods\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts","lineNumber":257,"sourceCode":"      currentCallDispatcher = callDispatcher;\n      const result = json ? JSON.parse(json, (key, initialValue) => {\n          // Invoke each reviver in order, passing the output from the previous reviver,\n          // so that each one gets a chance to transform the value\n\n          return jsonRevivers.reduce(\n              (latestValue, reviver) => reviver(key, latestValue),\n              initialValue\n          );\n      }) : null;\n      currentCallDispatcher = undefined;\n      return result;\n  }\n\n  function getDefaultCallDispatcher(): CallDispatcher {\n      if (defaultCallDispatcher === undefined) {\n          throw new Error(\"No call dispatcher has been set.\");\n      } else if (defaultCallDispatcher === null) {\n          throw new Error(\"There are multiple .NET runtimes present, so a default dispatcher could not be resolved. Use DotNetObject to invoke .NET instance methods.\");\n      } else {\n          return defaultCallDispatcher;\n      }\n  }\n\n  interface PendingAsyncCall<T> {\n    resolve: (value?: T | PromiseLike<T>) => void;\n    reject: (reason?: any) => void;\n  }\n\n  /**\n   * Represents the type of result expected from a JS interop call.\n   */\n  // eslint-disable-next-line no-shadow\n  export enum JSCallResultType {\n    Default = 0,\n    JSObjectReference = 1,\n    JSStreamReference = 2,","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts#L239-L275","documentation":"Thrown by getDefaultCallDispatcher() when defaultCallDispatcher is null, meaning attachDispatcher() was called more than once with different dispatchers. With multiple .NET runtimes loaded there is no single 'default' to route legacy static-style calls to, so the library refuses to guess. Callers must use a specific DotNetObject or dispatcher instance instead.","triggerScenarios":"Loading two Blazor runtimes on the same page (e.g., two Blazor WebAssembly roots, or Blazor Server + Blazor WebAssembly), each calling attachDispatcher. Then calling DotNet.invokeMethod / invokeMethodAsync (the module-level legacy APIs) hits the null default.","commonSituations":"Embedding multiple Blazor components from different apps on one page; mixing Blazor WebAssembly and Blazor Server in a host shell; testing harness that loads the runtime twice.","solutions":["Use a DotNetObjectReference from .NET and call invokeMethodAsync on that specific instance instead of the module-level DotNet.invokeMethodAsync.","Capture the specific ICallDispatcher returned by attachDispatcher and call invokeDotNetStaticMethodAsync on it.","Reduce to a single Blazor runtime per page if possible."],"exampleFix":"// before (ambiguous default)\nDotNet.invokeMethodAsync('MyLib', 'DoThing');\n\n// after (use the specific dispatcher / instance)\nconst dispatcher = DotNet.attachDispatcher(myDispatcher);\ndispatcher.invokeDotNetStaticMethodAsync('MyLib', 'DoThing');\n// or, from .NET, pass a DotNetObjectReference and call .invokeMethodAsync on it in JS","handlingStrategy":"validation","validationCode":"// Use a specific dispatcher / instance instead of the module-level default.\nconst dispatcher = DotNet.attachDispatcher(myDispatcher);\nawait dispatcher.invokeDotNetStaticMethodAsync('MyLib', 'Method');\n// or receive a DotNetObjectReference from .NET and call invokeMethodAsync on it.","typeGuard":null,"tryCatchPattern":"try { return await DotNet.invokeMethodAsync('MyLib', 'Method'); } catch (e) { if (/multiple .NET runtimes/.test(e.message)) { console.error('Use a specific DotNetObjectReference or captured dispatcher.'); } throw e; }","preventionTips":["Prefer DotNetObjectReference-based calls over module-level DotNet.invokeMethod*.","Capture the ICallDispatcher returned by attachDispatcher and route calls through it.","Load only one Blazor runtime per page when possible."],"tags":["js-interop","blazor","dispatcher","multi-runtime","lifecycle"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}