microsoft/aspire · error · DistributedApplicationException
Could not create HTTP command for resource
Error message
Could not create HTTP command for resource '{builder.Resource.Name}' as the endpoint selector returned null. What it means
HTTP resource commands (e.g. start/stop-style commands over HTTP) obtain their target endpoint by invoking a user-supplied or default endpoint selector. If the selector returns null there is no endpoint to send the request to, so Aspire throws DistributedApplicationException naming the resource.
Solutions
- Add or verify the resource declares an endpoint (WithEndpoint/WithHttpEndpoint) before the HTTP command is created
- Fix the custom selector so it returns an endpoint reference instead of null (check name/scheme filters)
- Add a fallback in the selector, e.g. endpoints.FirstOrDefault(e => e.Scheme == "http") ?? endpoints.First()
Example fix
// before
selector: () => endpoints.FirstOrDefault(e => e.EndpointName == "https") // null when only http exists
// after
selector: () => endpoints.FirstOrDefault(e => e.EndpointName == "https")
?? endpoints.First(e => e.Scheme == "http"); Defensive patterns
Strategy: type-guard
Validate before calling
var endpoints = builder.Resource.GetEndpoints().ToList();
if (endpoints.Count == 0) throw new InvalidOperationException("Resource has no endpoints for HTTP command"); Type guard
bool SelectorResolves(Func<EndpointReference?> selector) => selector() is not null;
Try / catch
try { builder.WithHttpCommand(...); }
catch (DistributedApplicationException ex) when (ex.Message.Contains("endpoint selector returned null")) { /* fix selector or add endpoint */ } Prevention
- Make custom endpoint selectors always fall back to a default endpoint
- Declare endpoints before creating HTTP commands that reference them
When it happens
Trigger: Passing a custom HttpCommandOptions.EndpointSelector (or equivalent selector parameter) whose function returns null — e.g. it filters endpoints by scheme/name and no endpoint matches; calling the API before the resource has any endpoint annotations.
Common situations: Selector logic that assumes an endpoint named 'https' exists when only 'http' is defined; endpoints added conditionally so they are missing in some run modes; running the command on a resource that never got an WithEndpoint call.
Related errors
- The HTTP command prepare-request callback returned null.
- BrowserMessageStrings.BrowserLogsResourceMissingHttpEndpoint
- Could not create for resource ' ' as the endpoint with name…
- Could not create for resource ' ' as no endpoint was found…
- Could not create HTTP command for resource
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/bd6a15b43c9d5e4b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting/ResourceBuilderExtensions.cs:3684
/// loadGenerator.WithReference(customerService);
/// </code>
/// </example>
/// <para>This method is not available in polyglot app hosts.</para>
/// </remarks>
[AspireExportIgnore(Reason = "Use the ATS-specific withHttpCommand export.")]
public static IResourceBuilder<TResource> WithHttpCommand<TResource>(
this IResourceBuilder<TResource> builder,
string path,
string displayName,
Func<EndpointReference>? endpointSelector,
string? commandName = null,
HttpCommandOptions? commandOptions = null)
where TResource : IResourceWithEndpoints
{
endpointSelector ??= DefaultEndpointSelector(builder);
var endpoint = endpointSelector()
?? throw new DistributedApplicationException($"Could not create HTTP command for resource '{builder.Resource.Name}' as the endpoint selector returned null.");
if (endpoint.Scheme != "http" && endpoint.Scheme != "https")
{
throw new DistributedApplicationException($"Could not create HTTP command for resource '{builder.Resource.Name}' as the endpoint with name '{endpoint.EndpointName}' and scheme '{endpoint.Scheme}' is not an HTTP endpoint.");
}
builder.ApplicationBuilder.Services.AddHttpClient();
commandOptions ??= HttpCommandOptions.Default;
commandOptions.Method ??= HttpMethod.Post;
commandName ??= $"{endpoint.Resource.Name}-{endpoint.EndpointName}-http-{commandOptions.Method.Method.ToLowerInvariant()}-{path}";
if (commandOptions.UpdateState is null)
{
commandOptions.UpdateState = context =>
{
var resourceState = context.ResourceSnapshot.State?.Text;View on GitHub (pinned to 25830f84bd)