{"record":{"id":"03e05184be457021","repo":"microsoft/aspire","slug":"getvalue-is-only-available-on-server-returned","errorCode":null,"errorMessage":"getValue is only available on server-returned ReferenceExpression instances","messagePattern":"getValue is only available on server-returned ReferenceExpression instances","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.CodeGeneration.Java/Resources/Base.java","lineNumber":233,"sourceCode":"                for (Object valueProvider : valueProviders) {\n                    providers.add(extractValueProvider(valueProvider));\n                }\n                expression.put(\"valueProviders\", providers);\n            }\n        }\n\n        Map<String, Object> result = new HashMap<>();\n        result.put(\"$expr\", expression);\n        return result;\n    }\n\n    public String getValue() {\n        return getValue(null);\n    }\n\n    public String getValue(CancellationToken cancellationToken) {\n        if (handle == null || client == null) {\n            throw new IllegalStateException(\"getValue is only available on server-returned ReferenceExpression instances\");\n        }\n\n        Map<String, Object> reqArgs = new HashMap<>();\n        reqArgs.put(\"context\", AspireClient.serializeValue(handle));\n        if (cancellationToken != null) {\n            reqArgs.put(\"cancellationToken\", cancellationToken);\n        }\n\n        return (String) client.invokeCapability(\"Aspire.Hosting.ApplicationModel/getValue\", reqArgs);\n    }\n\n    public static ReferenceExpression refExpr(String format, Object... valueProviders) {\n        return new ReferenceExpression(format, valueProviders);\n    }\n\n    public static ReferenceExpression createConditional(Object condition, String matchValue, ReferenceExpression whenTrue, ReferenceExpression whenFalse) {\n        return new ReferenceExpression(condition, matchValue, whenTrue, whenFalse);\n    }","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.CodeGeneration.Java/Resources/Base.java#L215-L251","documentation":"Aspire detects build-only container resources (containers whose image is built in the pipeline, e.g. for static assets) that no other resource consumes. Such containers would never participate in publish or deploy, which almost always indicates a wiring mistake, so ValidateBuildOnlyContainerReferences throws a DistributedApplicationException listing the unconsumed resources and the remedies.","triggerScenarios":"Adding a container via builder.AddDockerfile/AddContainer intended only as a build artifact but never referencing it from another resource via PublishWithContainerFiles or PublishWithStaticFiles; renaming/refactoring away the consuming resource.","commonSituations":"Using Dockerfile-based containers to build frontend assets and forgetting to attach them to the serving project; deleting the resource that consumed the build container; scaffolding a build container while prototyping and never wiring it up.","solutions":["Reference the container from the consuming resource, e.g. projectBuilder.PublishWithContainerFiles(container, \"/dist\") or .PublishWithStaticFiles(container).","If the container is intentionally unused (e.g. an experiment), remove the AddDockerfile/AddContainer registration.","Suppress the check deliberately with builder.Pipeline.DisableBuildOnlyContainerValidation() when the model is known-good.","Verify the resource name in the message matches the container you meant to consume; fix typos in the consuming call."],"exampleFix":"// before\nvar frontend = builder.AddDockerfile(\"frontend-build\", \"./frontend\");\n// after\nvar frontend = builder.AddDockerfile(\"frontend-build\", \"./frontend\");\nbuilder.AddProject<Projects.Api>(\"api\")\n    .PublishWithContainerFiles(frontend, \"/dist\");","handlingStrategy":"validation","validationCode":"// C#: ensure every Dockerfile/build container is referenced before execution\nvar buildContainers = appModel.Resources.Where(r => r.Annotations.OfType<DockerfileBuildAnnotation>().Any()).ToList();\nvar consumed = appModel.Resources.SelectMany(r => r.Annotations).OfType<ContainerFilesDestinationAnnotation>().Select(a => a.SourceResource.Name).ToHashSet();\nvar orphaned = buildContainers.Where(c => !consumed.Contains(c.Name)).ToList();\nif (orphaned.Count > 0) throw new InvalidOperationException($\"Unconsumed build containers: {string.Join(\", \", orphaned.Select(c => c.Name))}\");","typeGuard":null,"tryCatchPattern":"try\n{\n    await pipeline.ExecuteAsync(model);\n}\ncatch (DistributedApplicationException ex) when (ex.Message.Contains(\"Build-only container\"))\n{\n    logger.LogError(ex, \"Unconsumed build-only container: {Message}\", ex.Message);\n}","preventionTips":["Attach every Dockerfile container to a consumer (PublishWithContainerFiles / PublishWithStaticFiles) at registration time.","Only call DisableBuildOnlyContainerValidation when the orphan is intentional and documented.","Delete build-only containers when the consuming resource is removed."],"tags":["pipeline","docker","validation","aspire"],"backgroundTag":"missing-dependency","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"}