{"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":null,"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/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts#L464-L500","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["For instance calls, drop the assembly name: dotNetRef.invokeMethodAsync('Method', args).","For static calls, drop the dotNetObjectId: DotNet.invokeMethodAsync('Assembly','Method', args).","Audit any code calling the internal invokeDotNetMethodAsync(assembly, method, id, args) signature directly."],"exampleFix":"// before (wrong: both set)\nDotNet.invokeMethodAsync('MyAssembly', 'Method', 42, [arg]);\n\n// after (static)\nDotNet.invokeMethodAsync('MyAssembly', 'Method', null, [arg]);\n// or instance\ndotNetRef.invokeMethodAsync('Method', arg);","handlingStrategy":"validation","validationCode":"function invokeInstanceOrStatic(assemblyName, method, dotNetObjectId, args) {\n  if (assemblyName && dotNetObjectId) throw new Error('Pass either assemblyName (static) or dotNetObjectId (instance), not both.');\n  if (dotNetObjectId) return DotNet.invokeMethodAsync(null, method, dotNetObjectId, args);\n  return DotNet.invokeMethodAsync(assemblyName, method, null, args);\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Never pass assemblyName together with a dotNetObjectId.","Wrap interop in a single helper that enforces the mutual exclusion.","Prefer DotNetObject.invokeMethodAsync for instance calls so assemblyName is always null."],"tags":["blazor","jsinterop","validation","programming-error"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}