{"record":{"id":"5d6f638048f5edb9","repo":"dotnet/aspnetcore","slug":"for-instance-method-calls-assemblyname-should-be","errorCode":null,"errorMessage":"For instance method calls, assemblyName should be null. Received '${assemblyName}'.","messagePattern":"For instance method calls, assemblyName should be null\\. Received '(.+?)'\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts","lineNumber":482,"sourceCode":"      }\n\n      invokeDotNetStaticMethodAsync<T>(assemblyName: string, methodIdentifier: string, ...args: any[]): Promise<T> {\n          return this.invokeDotNetMethodAsync<T>(assemblyName, methodIdentifier, null, args);\n      }\n\n      invokeDotNetMethod<T>(assemblyName: string | null, methodIdentifier: string, dotNetObjectId: number | null, args: any[] | null): T | null {\n          if (this._dotNetCallDispatcher.invokeDotNetFromJS) {\n              const argsJson = stringifyArgs(this, args);\n              const resultJson = this._dotNetCallDispatcher.invokeDotNetFromJS(assemblyName, methodIdentifier, dotNetObjectId, argsJson);\n              return resultJson ? parseJsonWithRevivers(this, resultJson) : null;\n          }\n\n          throw new Error(\"The current dispatcher does not support synchronous calls from JS to .NET. Use invokeDotNetMethodAsync instead.\");\n      }\n\n      invokeDotNetMethodAsync<T>(assemblyName: string | null, methodIdentifier: string, dotNetObjectId: number | null, args: any[] | null): Promise<T> {\n          if (assemblyName && dotNetObjectId) {\n              throw new Error(`For instance method calls, assemblyName should be null. Received '${assemblyName}'.`);\n          }\n\n          const asyncCallId = this._nextAsyncCallId++;\n          const resultPromise = new Promise<T>((resolve, reject) => {\n              this._pendingAsyncCalls[asyncCallId] = { resolve, reject };\n          });\n\n          try {\n              const argsJson = stringifyArgs(this, args);\n              this._dotNetCallDispatcher.beginInvokeDotNetFromJS(asyncCallId, assemblyName, methodIdentifier, dotNetObjectId, argsJson);\n          } catch (ex) {\n              // Synchronous failure\n              this.completePendingCall(asyncCallId, false, ex);\n          }\n\n          return resultPromise;\n      }\n","sourceCodeStart":464,"sourceCodeEnd":500,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts#L464-L500","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ndispatcher.invokeDotNetMethodAsync('MyAssembly', 'Method', 42, args); // both set\n\n// after (instance call)\ndispatcher.invokeDotNetMethodAsync(null, 'Method', 42, args);\n// or prefer the public API\nmyDotNetObject.invokeMethodAsync('Method', ...args);","handlingStrategy":"validation","validationCode":"// For instance calls, always go through DotNetObject.invokeMethodAsync\n// which sets assemblyName=null internally.\nawait myDotNetObject.invokeMethodAsync('Method', ...args);","typeGuard":"function isValidInvokeTriple(asm, id) { return (asm && !id) || (!asm && id); }","tryCatchPattern":null,"preventionTips":["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."],"tags":["js-interop","blazor","dispatcher","instance-method","validation"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}