{"record":{"id":"a6b3fca5dde7e16d","repo":"microsoft/aspire","slug":"cannot-find-a-http-or-https-endpoint-for-this-resource-a6b3fc","errorCode":null,"errorMessage":"Cannot find a http or https endpoint for this resource.","messagePattern":"Cannot find a http or https endpoint for this resource\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Yarp/ConfigurationBuilder/YarpCluster.cs","lineNumber":139,"sourceCode":"        }\n    }\n\n    private static object[] BuildEndpointTargets(IResourceWithServiceDiscovery resource)\n    {\n        var resourceName = resource.Name;\n\n        var endpoints = resource.GetEndpoints()\n            .Where(e => e.Exists && !e.ExcludeReferenceEndpoint && (e.IsHttp || e.IsHttps))\n            .ToArray();\n        var schemeNamedEndpoints = endpoints\n            .Where(e => e.IsHttpSchemeNamedEndpoint)\n            .ToArray();\n\n        if (schemeNamedEndpoints.Length == 0)\n        {\n            if (endpoints.Length == 0)\n            {\n                throw new ArgumentException(\"Cannot find a http or https endpoint for this resource.\", nameof(resource));\n            }\n\n            return [.. endpoints.Select(BuildEndpointTarget)];\n        }\n\n        var hasHttpsEndpoint = schemeNamedEndpoints.Any(e => e.IsHttps);\n        var hasHttpEndpoint = schemeNamedEndpoints.Any(e => e.IsHttp);\n\n        var scheme = (hasHttpsEndpoint, hasHttpEndpoint) switch\n        {\n            (true, true) => \"https+http\",\n            (true, false) => \"https\",\n            (false, true) => \"http\",\n            _ => throw new ArgumentException(\"Cannot find a http or https endpoint for this resource.\", nameof(resource))\n        };\n\n        return [$\"{scheme}://{resourceName}\"];\n    }","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Yarp/ConfigurationBuilder/YarpCluster.cs#L121-L157","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add an HTTP(S) endpoint to the target resource, e.g. .WithHttpEndpoint(port: 8080) or ensure the project exposes http/https.","Target the correct resource — one that actually serves HTTP (a web project or service, not a database).","If the resource should derive its endpoint from another, reference the resource that owns the endpoint instead.","Check endpoint scheme names: the lookup only accepts http/https schemes, not custom-named tcp endpoints."],"exampleFix":"// before\nvar pg = builder.AddPostgres(\"pg\");\nyarp.AddRoute(\"/db\", pg); // no http endpoint on pg\n// after\nvar api = builder.AddProject<Projects.Api>(\"api\");\nyarp.AddRoute(\"/api\", api); // project with http/https endpoints","handlingStrategy":"validation","validationCode":"bool proxyable = resourceBuilder.Resource.GetEndpoints().Any(e =>\n    e.Endpoint?.Scheme is \"http\" or \"https\");","typeGuard":"static bool HasHttpEndpoint(IResource resource) =>\n    resource.GetEndpoints().Any(e => e.Endpoint?.Scheme is \"http\" or \"https\");","tryCatchPattern":"try { yarp.AddRoute(path, resourceBuilder); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"http or https endpoint\")) { /* choose another resource */ }","preventionTips":["Only proxy resources that expose http/https endpoints.","Add .WithHttpEndpoint to custom resources intended as proxy targets.","Check the resource's endpoint list in the dashboard before wiring YARP routes."],"tags":["yarp","endpoints","aspire"],"backgroundTag":"resource-not-found","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}