{"record":{"id":"70fc527cda85cff4","repo":"microsoft/aspire","slug":"aspire-build-returned-unexpected-type-t","errorCode":null,"errorMessage":"aspire: build returned unexpected type %T","messagePattern":"aspire: build returned unexpected type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.CodeGeneration.Go/AtsGoCodeGenerator.cs","lineNumber":2012,"sourceCode":"            // Synthesize an impl so wrapIfHandle can return a value satisfying\n            // the interface even when the metadata doesn't expose the application\n            // as a concrete handle type.\n            WriteLine($\"type {ToCamelCase(appInterface)} struct {{ *resourceBuilderBase }}\");\n            WriteLine();\n        }\n\n        // Build() method on the concrete impl. Sequential model: any prior\n        // chain error short-circuits; otherwise invoke the build capability\n        // and return the wrapped result.\n        WriteLine($\"// Build invokes the build capability and returns the running application.\");\n        WriteLine($\"func (b *{builderImpl}) Build() ({appInterface}, error) {{\");\n        WriteLine(\"\\tif b.err != nil { return nil, b.err }\");\n        WriteLine($\"\\tresult, err := b.client.invokeCapability(context.Background(), \\\"{AtsConstants.BuildCapability}\\\", map[string]any{{\");\n        WriteLine(\"\\t\\t\\\"context\\\": b.handle.ToJSON(),\");\n        WriteLine(\"\\t})\");\n        WriteLine(\"\\tif err != nil { return nil, err }\");\n        WriteLine($\"\\tapp, ok := result.({appInterface})\");\n        WriteLine($\"\\tif !ok {{ return nil, fmt.Errorf(\\\"aspire: build returned unexpected type %T\\\", result) }}\");\n        WriteLine(\"\\treturn app, nil\");\n        WriteLine(\"}\");\n        WriteLine();\n\n        // CreateBuilder factory.\n        var createOptionsType = GetCreateBuilderOptionsType(context);\n        WriteLine($\"// CreateBuilder establishes a connection to the AppHost and returns a new builder.\");\n        if (createOptionsType is not null)\n        {\n            WriteLine($\"func CreateBuilder(options ...*{createOptionsType}) ({builderInterface}, error) {{\");\n        }\n        else\n        {\n            WriteLine($\"func CreateBuilder() ({builderInterface}, error) {{\");\n        }\n        WriteLine(\"\\tsocketPath := os.Getenv(\\\"REMOTE_APP_HOST_SOCKET_PATH\\\")\");\n        WriteLine(\"\\tif socketPath == \\\"\\\" {\");\n        WriteLine(\"\\t\\treturn nil, fmt.Errorf(\\\"REMOTE_APP_HOST_SOCKET_PATH environment variable not set. Run this application using `aspire run`\\\")\");","sourceCodeStart":1994,"sourceCodeEnd":2030,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.CodeGeneration.Go/AtsGoCodeGenerator.cs#L1994-L2030","documentation":"The generated Build() method on the Go app builder invokes the 'build' capability and asserts the result implements the application interface. If the remote returns a different concrete type, this error is returned. It protects against protocol drift between the AppHost and generated Go client.","triggerScenarios":"Calling Build() on a generated Go builder when the remote 'build' capability returns a value that does not implement the expected app interface (e.g. nil or an unrelated handle).","commonSituations":"Version skew between the aspire AppHost and generated Go client, a failing/partial remote build returning an error payload instead of an app handle, or server-side bugs.","solutions":["Regenerate the Go client against the current AppHost contract","Update aspire CLI/AppHost and Go packages to matching versions","Check AppHost logs for why the build capability returned an unexpected value"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"app, err := b.Build()\nif err != nil {\n\treturn fmt.Errorf(\"build failed: %w\", err)\n}","preventionTips":["Keep AppHost and generated Go client in sync","Regenerate after contract changes to the build capability","Check AppHost logs when Build returns an unexpected-type error"],"tags":["go","code-generation","build","type-assertion","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"}