dotnet/aspnetcore · error · Error

For instance method calls, assemblyName should be null…

Error message

For instance method calls, assemblyName should be null. Received '${assemblyName}'.

What it means

Thrown by CallDispatcher.invokeDotNetMethodAsync() when both assemblyName and dotNetObjectId are truthy. Instance method calls are routed by dotNetObjectId alone; supplying an assemblyName too is ambiguous, so the library rejects it. Static calls pass assemblyName with dotNetObjectId=null; instance calls pass dotNetObjectId with assemblyName=null.

Solutions

  1. For instance method calls, pass null for assemblyName — call via DotNetObject.invokeMethodAsync which does this correctly.
  2. For static calls, pass null for dotNetObjectId.
  3. Audit custom dispatcher call sites for the (assemblyName, method, dotNetObjectId) triple.

Example fix

// before
dispatcher.invokeDotNetMethodAsync('MyAssembly', 'Method', 42, args); // both set

// after (instance call)
dispatcher.invokeDotNetMethodAsync(null, 'Method', 42, args);
// or prefer the public API
myDotNetObject.invokeMethodAsync('Method', ...args);
Defensive patterns

Strategy: validation

Validate before calling

// For instance calls, always go through DotNetObject.invokeMethodAsync
// which sets assemblyName=null internally.
await myDotNetObject.invokeMethodAsync('Method', ...args);

Type guard

function isValidInvokeTriple(asm, id) { return (asm && !id) || (!asm && id); }

Prevention

When it happens

Trigger: Calling invokeMethodAsync on a DotNetObject while also passing an assembly name, or a misuse of the lower-level invokeDotNetMethodAsync(assemblyName, method, dotNetObjectId, args) with both set. The public DotNetObject.invokeMethodAsync always passes null for assemblyName, so this typically comes from custom dispatcher usage.

Common situations: Custom host code building the 4-arg call incorrectly; a wrapper that forwards assemblyName through to instance invocations; confusion about static vs instance interop signatures.

Related errors


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

Appendix: source

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

      }

      invokeDotNetStaticMethodAsync<T>(assemblyName: string, methodIdentifier: string, ...args: any[]): Promise<T> {
          return this.invokeDotNetMethodAsync<T>(assemblyName, methodIdentifier, null, args);
      }

      invokeDotNetMethod<T>(assemblyName: string | null, methodIdentifier: string, dotNetObjectId: number | null, args: any[] | null): T | null {
          if (this._dotNetCallDispatcher.invokeDotNetFromJS) {
              const argsJson = stringifyArgs(this, args);
              const resultJson = this._dotNetCallDispatcher.invokeDotNetFromJS(assemblyName, methodIdentifier, dotNetObjectId, argsJson);
              return resultJson ? parseJsonWithRevivers(this, resultJson) : null;
          }

          throw new Error("The current dispatcher does not support synchronous calls from JS to .NET. Use invokeDotNetMethodAsync instead.");
      }

      invokeDotNetMethodAsync<T>(assemblyName: string | null, methodIdentifier: string, dotNetObjectId: number | null, args: any[] | null): Promise<T> {
          if (assemblyName && dotNetObjectId) {
              throw new Error(`For instance method calls, assemblyName should be null. Received '${assemblyName}'.`);
          }

          const asyncCallId = this._nextAsyncCallId++;
          const resultPromise = new Promise<T>((resolve, reject) => {
              this._pendingAsyncCalls[asyncCallId] = { resolve, reject };
          });

          try {
              const argsJson = stringifyArgs(this, args);
              this._dotNetCallDispatcher.beginInvokeDotNetFromJS(asyncCallId, assemblyName, methodIdentifier, dotNetObjectId, argsJson);
          } catch (ex) {
              // Synchronous failure
              this.completePendingCall(asyncCallId, false, ex);
          }

          return resultPromise;
      }

View on GitHub (pinned to 3600ca084e)