{"record":{"id":"36e0bb3b3b36d11a","repo":"microsoft/aspire","slug":"could-not-create-http-command-for-resource-builder-resource-36e0bb","errorCode":null,"errorMessage":"Could not create HTTP command for resource '{builder.Resource.Name}' as it has no HTTP endpoints.","messagePattern":"Could not create HTTP command for resource '(.+?)' as it has no HTTP endpoints\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/ResourceBuilderExtensions.cs","lineNumber":4410,"sourceCode":"\n    private static Func<EndpointReference> DefaultEndpointSelector<TResource>(IResourceBuilder<TResource> builder)\n        where TResource : IResourceWithEndpoints\n        => () =>\n        {\n            // Use the first HTTP endpoint (preferring HTTPS over HTTP), otherwise throw an exception if no endpoint is found.\n            var endpoints = builder.Resource.GetEndpoints();\n            EndpointReference? matchingEndpoint = null;\n\n            foreach (var scheme in s_httpSchemes)\n            {\n                matchingEndpoint = endpoints.FirstOrDefault(e => string.Equals(e.EndpointName, scheme, StringComparisons.EndpointAnnotationUriScheme));\n                if (matchingEndpoint is not null)\n                {\n                    return matchingEndpoint;\n                }\n            }\n\n            throw new DistributedApplicationException($\"Could not create HTTP command for resource '{builder.Resource.Name}' as it has no HTTP endpoints.\");\n        };\n\n    /// <summary>\n    /// Adds a <see cref=\"ResourceRelationshipAnnotation\"/> to the resource annotations to add a relationship.\n    /// </summary>\n    /// <typeparam name=\"T\">The type of the resource.</typeparam>\n    /// <param name=\"builder\">The resource builder.</param>\n    /// <param name=\"resource\">The resource that the relationship is to.</param>\n    /// <param name=\"type\">The relationship type.</param>\n    /// <returns>A resource builder.</returns>\n    /// <remarks>\n    /// <para>\n    /// The <c>WithRelationship</c> method is used to add relationships to the resource. Relationships are used to link\n    /// resources together in UI. The <paramref name=\"type\"/> indicates information about the relationship type.\n    /// </para>\n    /// <example>\n    /// This example shows adding a relationship between two resources.\n    /// <code lang=\"C#\">","sourceCodeStart":4392,"sourceCodeEnd":4428,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ResourceBuilderExtensions.cs#L4392-L4428","documentation":"Aspire throws this DistributedApplicationException when WithHttpCommand (or a related HTTP command API) is asked to create an HTTP command for a resource that has no HTTP endpoints defined. HTTP commands need an endpoint to target so the command can issue an HTTP request against the running resource. The library refuses to build a command that would have nothing to send a request to.","triggerScenarios":"Calling WithHttpCommand on a resource builder whose resource (e.g. a project or container) has no endpoint added via WithEndpoint/WithHttpEndpoint/WithHttpsEndpoint, or where the endpoint filter excludes all endpoints.","commonSituations":"Adding an HTTP command like 'restart' or 'migrate database' to a container that only exposes a TCP port, forgetting WithEndpoint before WithHttpCommand, or a resource whose endpoints are added conditionally (e.g. only in run mode).","solutions":["Add an HTTP endpoint to the resource before adding the command, e.g. .WithHttpEndpoint(port: 8080)","Verify the endpointSelector/filter passed to WithHttpCommand matches an existing endpoint (check scheme and endpoint name)","Reorder builder calls so endpoint registration precedes WithHttpCommand"],"exampleFix":"// before\nvar redis = builder.AddContainer(\"redis\", \"redis\").WithHttpCommand(\"/flush\");\n// after\nvar redis = builder.AddContainer(\"redis\", \"redis\")\n    .WithHttpEndpoint(port: 8080)\n    .WithHttpCommand(\"/flush\");","handlingStrategy":"validation","validationCode":"var hasHttpEndpoint = resourceBuilder.Resource.Annotations\n    .OfType<EndpointAnnotation>()\n    .Any(e => e.UriScheme is \"http\" or \"https\");\nif (!hasHttpEndpoint) throw new InvalidOperationException(\"Resource needs an HTTP endpoint before WithHttpCommand.\");","typeGuard":null,"tryCatchPattern":"try { builder.WithHttpCommand(\"/admin/reload\"); }\ncatch (DistributedApplicationException ex) { logger.LogWarning(ex, \"No HTTP endpoint for {Resource}; command skipped\", builder.Resource.Name); }","preventionTips":["Always call WithHttpEndpoint/WithHttpsEndpoint before WithHttpCommand","Keep endpoint registration and command registration adjacent in builder chains","Be careful with conditional endpoint registration in publish mode"],"tags":["aspire","http","endpoints","configuration"],"backgroundTag":"resource-not-found","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"}