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
- For instance method calls, pass null for assemblyName — call via DotNetObject.invokeMethodAsync which does this correctly.
- For static calls, pass null for dotNetObjectId.
- 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
- Use the public DotNetObject API for instance calls rather than the low-level dispatcher method.
- For static calls pass dotNetObjectId=null; for instance calls pass assemblyName=null.
- Audit custom dispatcher call sites for the (assemblyName, method, dotNetObjectId) triple.
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
- No call dispatcher has been set.
- The current dispatcher does not support synchronous calls…
- There are multiple .NET runtimes present, so a default…
- There is no pending async call with ID
- assembly must be defined when using a descriptor.
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)