{"record":{"id":"82ffa23c683588ab","repo":"microsoft/aspire","slug":"aspire-capability-capabilityid-returned-unexpected-type-t","errorCode":null,"errorMessage":"aspire: {capability.CapabilityId} returned unexpected type %T","messagePattern":"aspire: (.+?) returned unexpected type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.CodeGeneration.Go/AtsGoCodeGenerator.cs","lineNumber":1310,"sourceCode":"            ? implTarget\n            : null;\n\n        if (childImplName is null)\n        {\n            // No registered impl for this typeId (e.g. *ReferenceExpression,\n            // which is hand-written in base.go). Cast the wrapIfHandle result\n            // directly to the declared return type. Errors land on s; we\n            // return nil and the caller must consult s.Err().\n            var returnGoType = MapTypeRefToGo(returnType, false);\n            WriteLine(\"\\tif s.err != nil { return nil }\");\n            EmitHandleParamErrorChecks(\"\\t\", capability, \"s.setErr(err); return nil\");\n            EmitUnionTypeChecks(\"\\t\", capability, methodName, new[] { \"s.setErr(err); return nil\" });\n            EmitArgsConstruction(\"\\t\", capability, requiredParams, optionalParams, targetParamName, \"s.handle\");\n                WriteLine($\"\\tresult, err := s.client.invokeCapability(ctx, \\\"{capability.CapabilityId}\\\", reqArgs)\");\n            WriteLine(\"\\tif err != nil { s.setErr(err); return nil }\");\n            WriteLine($\"\\ttyped, ok := result.({returnGoType})\");\n            WriteLine(\"\\tif !ok {\");\n            WriteLine($\"\\t\\ts.setErr(fmt.Errorf(\\\"aspire: {capability.CapabilityId} returned unexpected type %T\\\", result))\");\n            WriteLine(\"\\t\\treturn nil\");\n            WriteLine(\"\\t}\");\n            WriteLine(\"\\treturn typed\");\n            return;\n        }\n\n        // Pre-errored child path: parent failure short-circuits this call.\n        WriteLine($\"\\tif s.err != nil {{ return &{childImplName}{{resourceBuilderBase: newErroredResourceBuilder(s.err, s.client)}} }}\");\n        EmitHandleParamErrorChecks(\"\\t\", capability,\n            $\"return &{childImplName}{{resourceBuilderBase: newErroredResourceBuilder(err, s.client)}}\");\n        EmitUnionTypeChecks(\"\\t\", capability, methodName, new[]\n        {\n            $\"return &{childImplName}{{resourceBuilderBase: newErroredResourceBuilder(err, s.client)}}\",\n        });\n        EmitArgsConstruction(\"\\t\", capability, requiredParams, optionalParams, targetParamName, \"s.handle\");\n        WriteLine($\"\\tresult, err := s.client.invokeCapability(ctx, \\\"{capability.CapabilityId}\\\", reqArgs)\");\n        WriteLine(\"\\tif err != nil {\");\n        WriteLine($\"\\t\\treturn &{childImplName}{{resourceBuilderBase: newErroredResourceBuilder(err, s.client)}}\");","sourceCodeStart":1292,"sourceCodeEnd":1328,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.CodeGeneration.Go/AtsGoCodeGenerator.cs#L1292-L1328","documentation":"Generated Go capability methods invoke the capability over the socket and then assert the returned value has the expected Go type. If the remote side returns something of a different concrete type, the type assertion fails and this error is stored on the errored builder. It signals a protocol/shape mismatch between the AppHost and the generated client.","triggerScenarios":"A capability invoked via a generated method (with a declared return type) returns a value whose Go concrete type does not match the generated returnGoType assertion.","commonSituations":"Mismatched versions of the AppHost and the generated Go client (contract drift), a server-side bug returning nil or a different handle type, or custom/patched capability implementations.","solutions":["Regenerate the Go client from the current AppHost so return types match the live capability contract","Upgrade the AppHost/CLI and Go client to matching versions","Inspect the server-side capability implementation to confirm it returns the declared type"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"result, err := client.SomeCapability(ctx, arg)\nif err != nil {\n\t// covers type-mismatch errors stored by setErr\n\treturn fmt.Errorf(\"capability call failed: %w\", err)\n}","preventionTips":["Keep the AppHost and generated Go client versions in lockstep","Regenerate the client after any capability return-type change","Log %T of results when debugging protocol mismatches"],"tags":["go","code-generation","type-assertion","ats","version-mismatch"],"backgroundTag":"unexpected-response-shape","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"}