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

This helper builds the canonical http(s) service URL reference for a resource and requires at least one http or https endpoint. When the resource has neither (the (false,false) switch case), it throws an ArgumentException naming the resource parameter.

Solutions

  1. Add an http or https endpoint to the resource, e.g. .WithHttpEndpoint(...) or .WithHttpsEndpoint(...), before generating the URL.
  2. Check hasHttpsEndpoint/hasHttpEndpoint detection by ensuring endpoint annotations exist on the exact resource passed in.
  3. If the resource legitimately has no endpoint, don't call this helper — construct the URL from configuration instead.

Example fix

// before
var app = builder.AddNpmApp("frontend", "./frontend");
var url = app.GetHttpUrl(); // throws
// after
var app = builder.AddNpmApp("frontend", "./frontend").WithHttpEndpoint(port: 3000);
var url = app.GetHttpUrl();
Defensive patterns

Strategy: validation

Validate before calling

var endpoints = resource.Resource.Annotations.OfType<EndpointAnnotation>().ToList();
if (!endpoints.Any(e => e.UriScheme is "http" or "https"))
    throw new ArgumentException("Resource needs an http/https endpoint before generating its URL.");

Try / catch

try { var url = ResourceUrlHelpers.GetUrl(resource); } catch (ArgumentException ex) when (ex.Message.Contains("http or https endpoint")) { /* configure endpoint first */ }

Prevention

When it happens

Trigger: Calling GetEndpoint-style URL helpers (e.g. the resource URL extension behind AddNextJsApp/JavaScript resources) on a resource with no http/https endpoint annotations.

Common situations: Calling the URL helper before endpoints are configured, on an endpoint-less worker resource, or after removing endpoints with a callback.

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/5a0cf0a7eb5ff832. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs:3148

    private static readonly string[] s_nextConfigFileNames = ["next.config.ts", "next.config.js", "next.config.mjs"];

    /// <summary>
    /// Builds a service discovery URL for the given resource, preferring HTTPS when available.
    /// Mirrors the logic in <c>YarpCluster.BuildEndpointUri</c>.
    /// </summary>
    private static string BuildServiceDiscoveryUrl(IResourceWithServiceDiscovery resource)
    {
        var endpoints = resource.GetEndpoints();
        var hasHttpsEndpoint = endpoints.Any(e => e.Exists && e.IsHttps);
        var hasHttpEndpoint = endpoints.Any(e => e.Exists && 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}://{resource.Name}";
    }

    /// <summary>
    /// Validates that the Next.js config file contains <c>output: "standalone"</c>.
    /// </summary>
    internal static void ValidateNextJsStandaloneOutput(string appDirectory)
    {
        foreach (var configFileName in s_nextConfigFileNames)
        {
            var configPath = Path.Combine(appDirectory, configFileName);
            if (!File.Exists(configPath))
            {
                continue;
            }

View on GitHub (pinned to 25830f84bd)