microsoft/aspire · error · ArgumentException

Cannot find a http or https endpoint for this resource.

Error message

Cannot find a http or https endpoint for this resource.

What it means

YarpCluster.BuildEndpointTargets resolves which endpoints of a target resource back the YARP cluster. When no endpoint on the resource has an http or https scheme and no endpoints exist at all, it throws this ArgumentException because there is no addressable HTTP destination for the proxy.

Solutions

  1. Add an HTTP(S) endpoint to the target resource, e.g. .WithHttpEndpoint(port: 8080) or ensure the project exposes http/https.
  2. Target the correct resource — one that actually serves HTTP (a web project or service, not a database).
  3. If the resource should derive its endpoint from another, reference the resource that owns the endpoint instead.
  4. Check endpoint scheme names: the lookup only accepts http/https schemes, not custom-named tcp endpoints.

Example fix

// before
var pg = builder.AddPostgres("pg");
yarp.AddRoute("/db", pg); // no http endpoint on pg
// after
var api = builder.AddProject<Projects.Api>("api");
yarp.AddRoute("/api", api); // project with http/https endpoints
Defensive patterns

Strategy: validation

Validate before calling

bool proxyable = resourceBuilder.Resource.GetEndpoints().Any(e =>
    e.Endpoint?.Scheme is "http" or "https");

Type guard

static bool HasHttpEndpoint(IResource resource) =>
    resource.GetEndpoints().Any(e => e.Endpoint?.Scheme is "http" or "https");

Try / catch

try { yarp.AddRoute(path, resourceBuilder); }
catch (ArgumentException ex) when (ex.Message.Contains("http or https endpoint")) { /* choose another resource */ }

Prevention

When it happens

Trigger: Adding a route targeting a resource builder whose resource exposes zero endpoints (or only non-HTTP endpoints like tcp/udp), causing ResolveTargets -> BuildEndpointTargets to find nothing.

Common situations: Targeting a database or plain container resource with no HTTP endpoint; forgetting WithEndpoint/WithHttpEndpoint on a custom resource; typo in endpoint name filtering; targeting a project before endpoints are defined via WithServiceDiscovery.

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


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

Appendix: source

Thrown at src/Aspire.Hosting.Yarp/ConfigurationBuilder/YarpCluster.cs:139

        }
    }

    private static object[] BuildEndpointTargets(IResourceWithServiceDiscovery resource)
    {
        var resourceName = resource.Name;

        var endpoints = resource.GetEndpoints()
            .Where(e => e.Exists && !e.ExcludeReferenceEndpoint && (e.IsHttp || e.IsHttps))
            .ToArray();
        var schemeNamedEndpoints = endpoints
            .Where(e => e.IsHttpSchemeNamedEndpoint)
            .ToArray();

        if (schemeNamedEndpoints.Length == 0)
        {
            if (endpoints.Length == 0)
            {
                throw new ArgumentException("Cannot find a http or https endpoint for this resource.", nameof(resource));
            }

            return [.. endpoints.Select(BuildEndpointTarget)];
        }

        var hasHttpsEndpoint = schemeNamedEndpoints.Any(e => e.IsHttps);
        var hasHttpEndpoint = schemeNamedEndpoints.Any(e => e.IsHttp);

        var scheme = (hasHttpsEndpoint, hasHttpEndpoint) switch
        {
            (true, true) => "https+http",
            (true, false) => "https",
            (false, true) => "http",
            _ => throw new ArgumentException("Cannot find a http or https endpoint for this resource.", nameof(resource))
        };

        return [$"{scheme}://{resourceName}"];
    }

View on GitHub (pinned to 25830f84bd)