dotnet/aspnetcore · error

For instance method calls, assemblyName should be null. Rece

Error message

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

What it means

Thrown in invokeDotNetMethodAsync when both assemblyName and dotNetObjectId are truthy at the same time. The .NET invocation contract is exclusive: a static method is addressed by (assemblyName, methodIdentifier) with a null instance id, while an instance method is addressed by (dotNetObjectId, methodIdentifier) with a null assembly. Passing both is ambiguous and rejected up front.

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 294cab2f9b)

Solutions

  1. For instance calls, drop the assembly name: dotNetRef.invokeMethodAsync('Method', args).
  2. For static calls, drop the dotNetObjectId: DotNet.invokeMethodAsync('Assembly','Method', args).
  3. Audit any code calling the internal invokeDotNetMethodAsync(assembly, method, id, args) signature directly.

Example fix

// before (wrong: both set)
DotNet.invokeMethodAsync('MyAssembly', 'Method', 42, [arg]);

// after (static)
DotNet.invokeMethodAsync('MyAssembly', 'Method', null, [arg]);
// or instance
dotNetRef.invokeMethodAsync('Method', arg);
Defensive patterns

Strategy: validation

Validate before calling

function invokeInstanceOrStatic(assemblyName, method, dotNetObjectId, args) {
  if (assemblyName && dotNetObjectId) throw new Error('Pass either assemblyName (static) or dotNetObjectId (instance), not both.');
  if (dotNetObjectId) return DotNet.invokeMethodAsync(null, method, dotNetObjectId, args);
  return DotNet.invokeMethodAsync(assemblyName, method, null, args);
}

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: Manually constructing a DotNet.invoke call with all four arguments set, e.g. DotNet.invokeMethodAsync('MyAssembly','Method', dotNetObjectId, args) with a non-null dotNetObjectId. Or a wrapper that forwards an assembly name into a DotNetObject-style call. The public DotNetObject.invokeMethodAsync always passes null for assemblyName (Microsoft.JSInterop.ts:714), so this is only hit via the lower-level API or misuse.

Common situations: Copy-paste between static and instance invocation patterns; passing a DotNetObjectRef JSON blob plus assembly name in custom interop; refactoring that accidentally leaves the assembly argument populated.

Related errors


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