microsoft/aspire · error · DistributedApplicationException

Could not create for resource ' ' as the endpoint with name…

Error message

Could not create {errorDisplayNoun} for resource '{builder.Resource.Name}' as the endpoint with name '{matchingEndpoint.EndpointName}' and scheme '{matchingEndpoint.Scheme}' is not an HTTP endpoint.

What it means

When creating an HTTP-based resource command with an explicit endpoint name, Aspire looks up the endpoint by name and verifies its scheme is http/https. If the named endpoint exists but has a non-HTTP scheme (e.g. tcp), it throws DistributedApplicationException identifying the endpoint and its scheme.

Solutions

  1. Declare (or select) an endpoint with scheme http or https for the HTTP command
  2. Fix the scheme typo in the WithEndpoint call if the endpoint is actually HTTP
  3. Use a different endpointName that refers to the HTTP endpoint

Example fix

// before
.WithEndpoint(name: "admin", scheme: "tcp") // later used for HTTP command
// after
.WithEndpoint(name: "admin", scheme: "https")
Defensive patterns

Strategy: validation

Validate before calling

var ep = resource.GetEndpoint(endpointName);
if (ep is { } resolved && !s_httpSchemes.Contains(resolved.Scheme))
    throw new InvalidOperationException($"Endpoint '{endpointName}' scheme '{resolved.Scheme}' is not HTTP");

Type guard

bool IsHttpScheme(string? scheme) => scheme is "http" or "https";

Try / catch

try { builder.WithHttpCommand(..., endpointName: name); }
catch (DistributedApplicationException ex) when (ex.Message.Contains("is not an HTTP endpoint")) { /* redeclare endpoint with http/https */ }

Prevention

When it happens

Trigger: Calling WithHttpCommand (or similar) with an endpointName that matches an endpoint declared via WithEndpoint(scheme: "tcp") or another non-HTTP scheme.

Common situations: Reusing an endpoint name defined for a raw TCP/UDP port; a scheme typo in the endpoint declaration ('htps'); endpoints declared programmatically with custom schemes for internal protocols.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/39a1cf77205f7db8. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting/ResourceBuilderExtensions.cs:4382

    // if found.
    private static readonly string[] s_httpSchemes = ["https", "http"];

    private static Func<EndpointReference> NamedEndpointSelector<TResource>(IResourceBuilder<TResource> builder, string[] endpointNames, string errorDisplayNoun)
        where TResource : IResourceWithEndpoints
        => () =>
        {
            // Find a matching endpoint using those names and if not an HTTP endpoint or not found throw an exception.
            var endpoints = builder.Resource.GetEndpoints();
            EndpointReference? matchingEndpoint = null;

            foreach (var name in endpointNames)
            {
                matchingEndpoint = endpoints.FirstOrDefault(e => string.Equals(e.EndpointName, name, StringComparisons.EndpointAnnotationName));
                if (matchingEndpoint is not null)
                {
                    if (!s_httpSchemes.Contains(matchingEndpoint.Scheme, StringComparers.EndpointAnnotationUriScheme))
                    {
                        throw new DistributedApplicationException($"Could not create {errorDisplayNoun} for resource '{builder.Resource.Name}' as the endpoint with name '{matchingEndpoint.EndpointName}' and scheme '{matchingEndpoint.Scheme}' is not an HTTP endpoint.");
                    }
                    return matchingEndpoint;
                }
            }

            // No endpoint found with the specified names
            var endpointNamesString = string.Join(", ", endpointNames);
            throw new DistributedApplicationException($"Could not create {errorDisplayNoun} for resource '{builder.Resource.Name}' as no endpoint was found matching one of the specified names: {endpointNamesString}");
        };

    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;

View on GitHub (pinned to 25830f84bd)