{"record":{"id":"c4e7304330b72ac0","repo":"microsoft/aspire","slug":"type-mismatch","errorCode":"TYPE_MISMATCH","errorMessage":"Could not invoke '{methodName}': {scrubbedMessage}","messagePattern":"Could not invoke '(.+?)': (.+?)","errorType":"error_code","errorClass":"PolyglotCapabilityInvocationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.RemoteHost/Ats/CapabilityDispatcher.cs","lineNumber":566,"sourceCode":"\n        try\n        {\n            return await registration.Handler(args, _handles).ConfigureAwait(false);\n        }\n        catch (PolyglotCapabilityInvocationException ex)\n        {\n            activity.SetError(ex);\n            throw ex.ToCapabilityException();\n        }\n        catch (CapabilityException ex)\n        {\n            activity.SetError(ex);\n            throw;\n        }\n        catch (ArgumentException ex) when (IsTypeMismatchException(ex))\n        {\n            activity.SetError(ex);\n            throw PolyglotCapabilityErrorFormatter.CreateInternalError(\n                capabilityId,\n                registration.Capability?.MethodName,\n                registration.ClrMemberName,\n                args,\n                _handles,\n                ex,\n                _polyglotMethodNamesByClrName,\n                registration.Capability?.TargetParameterName,\n                errorCode: AtsErrorCodes.TypeMismatch).ToCapabilityException();\n        }\n        catch (ArgumentException ex)\n        {\n            activity.SetError(ex);\n            throw CapabilityException.InvalidArgument(\n                capabilityId,\n                ex.ParamName ?? registration.Capability?.TargetParameterName ?? \"unknown\",\n                ex.Message);\n        }","sourceCodeStart":548,"sourceCodeEnd":584,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.RemoteHost/Ats/CapabilityDispatcher.cs#L548-L584","documentation":"When a registered capability method invocation fails with an ArgumentException classified as a type mismatch, the dispatcher converts it into a TYPE_MISMATCH PolyglotCapabilityError formatted as \"Could not invoke '{methodName}': {scrubbedMessage}\". It signals that an argument supplied to the remote capability did not match the expected parameter type.","triggerScenarios":"InvokeAsync -> a capability registration's target method throws ArgumentException detected by IsTypeMismatchException (e.g. wrong enum/parameter value type), commonly when a client passes an argument of the wrong shape via the polyglot/ATS bridge.","commonSituations":"Cross-language (polyglot) clients passing JS/Python values that don't map to the CLR parameter type; handle misuse (passing a handle of the wrong kind); stale clients calling capabilities after signature changes.","solutions":["Check the capability's registered signature and pass arguments matching the declared parameter types","Verify handles being passed are of the correct type/registration","Update the client SDK/version to match the host's capability contract","Scrub and read the {scrubbedMessage} detail to identify which parameter failed"],"exampleFix":"// before\nawait dispatcher.InvokeAsync(\"addResource\", 42); // string expected\n// after\nawait dispatcher.InvokeAsync(\"addResource\", \"my-resource\");","handlingStrategy":"try-catch","validationCode":"// Validate argument types against the capability signature before invoking\nif (arg is not string s) throw new ArgumentException(\"addResource expects a string\", nameof(arg));","typeGuard":"bool IsMatchingType(object? arg, Type expected) => arg is null ? !expected.IsValueType || Nullable.GetUnderlyingType(expected) is not null : expected.IsInstanceOfType(arg);","tryCatchPattern":"try { await dispatcher.InvokeAsync(methodName, args); }\ncatch (PolyglotCapabilityError ex) when (ex.Code == \"TYPE_MISMATCH\") { /* fix argument types per capability signature */ }","preventionTips":["Check the capability's registered signature before invoking","Match argument types exactly when crossing the polyglot bridge","Keep client SDK versions in sync with host capability contracts"],"tags":["type-mismatch","capability","remote-host","arguments"],"backgroundTag":"type-mismatch","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}