microsoft/aspire · error · DistributedApplicationException
Could not create HTTP command for resource
Error message
Could not create HTTP command for resource '{builder.Resource.Name}' as it has no HTTP endpoints. What it means
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.
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
Example fix
// before
var redis = builder.AddContainer("redis", "redis").WithHttpCommand("/flush");
// after
var redis = builder.AddContainer("redis", "redis")
.WithHttpEndpoint(port: 8080)
.WithHttpCommand("/flush"); Defensive patterns
Strategy: validation
Validate before calling
var hasHttpEndpoint = resourceBuilder.Resource.Annotations
.OfType<EndpointAnnotation>()
.Any(e => e.UriScheme is "http" or "https");
if (!hasHttpEndpoint) throw new InvalidOperationException("Resource needs an HTTP endpoint before WithHttpCommand."); Try / catch
try { builder.WithHttpCommand("/admin/reload"); }
catch (DistributedApplicationException ex) { logger.LogWarning(ex, "No HTTP endpoint for {Resource}; command skipped", builder.Resource.Name); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Could not create HTTP probe for resource
- The endpoint ` ` is not defined for the resource ` `. The…
- AllocatedEndpoint must use the same network as the…
- At least one gateway endpoint (HTTP or HTTPS) must be…
- BrowserMessageStrings.BrowserLogsResourceMissingHttpEndpoint
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/36e0bb3b3b36d11a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting/ResourceBuilderExtensions.cs:4410
private static Func<EndpointReference> DefaultEndpointSelector<TResource>(IResourceBuilder<TResource> builder)
where TResource : IResourceWithEndpoints
=> () =>
{
// Use the first HTTP endpoint (preferring HTTPS over HTTP), otherwise throw an exception if no endpoint is found.
var endpoints = builder.Resource.GetEndpoints();
EndpointReference? matchingEndpoint = null;
foreach (var scheme in s_httpSchemes)
{
matchingEndpoint = endpoints.FirstOrDefault(e => string.Equals(e.EndpointName, scheme, StringComparisons.EndpointAnnotationUriScheme));
if (matchingEndpoint is not null)
{
return matchingEndpoint;
}
}
throw new DistributedApplicationException($"Could not create HTTP command for resource '{builder.Resource.Name}' as it has no HTTP endpoints.");
};
/// <summary>
/// Adds a <see cref="ResourceRelationshipAnnotation"/> to the resource annotations to add a relationship.
/// </summary>
/// <typeparam name="T">The type of the resource.</typeparam>
/// <param name="builder">The resource builder.</param>
/// <param name="resource">The resource that the relationship is to.</param>
/// <param name="type">The relationship type.</param>
/// <returns>A resource builder.</returns>
/// <remarks>
/// <para>
/// The <c>WithRelationship</c> method is used to add relationships to the resource. Relationships are used to link
/// resources together in UI. The <paramref name="type"/> indicates information about the relationship type.
/// </para>
/// <example>
/// This example shows adding a relationship between two resources.
/// <code lang="C#">View on GitHub (pinned to 25830f84bd)