{"record":{"id":"87327f26ea4f2876","repo":"microsoft/aspire","slug":"resource-0-has-no-allocated-endpoints","errorCode":null,"errorMessage":"Resource '{0}' has no allocated endpoints.","messagePattern":"Resource '(.+?)' has no allocated endpoints\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Testing/DistributedApplicationHostingTestingExtensions.cs","lineNumber":270,"sourceCode":"    static IResource GetResource(DistributedApplication app, string resourceName)\n    {\n        ThrowIfNotStarted(app, Properties.Resources.ApplicationNotStartedExceptionMessage);\n        var applicationModel = app.Services.GetRequiredService<DistributedApplicationModel>();\n\n        if (!applicationModel.Resources.TryGetByName(resourceName, out var resource))\n        {\n            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.ResourceNotFoundExceptionMessage, resourceName), nameof(resourceName));\n        }\n\n        return resource;\n    }\n\n    static string GetEndpointUriStringCore(DistributedApplication app, string resourceName, string? endpointName = default, NetworkIdentifier? networkIdentifier = default)\n    {\n        var resource = GetResource(app, resourceName);\n        if (resource is not IResourceWithEndpoints resourceWithEndpoints)\n        {\n            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.ResourceHasNoAllocatedEndpointsExceptionMessage, resourceName), nameof(resourceName));\n        }\n\n        EndpointReference? endpoint;\n        if (!string.IsNullOrEmpty(endpointName))\n        {\n            endpoint = GetEndpointOrDefault(resourceWithEndpoints, endpointName, networkIdentifier);\n        }\n        else\n        {\n            // Prefer https over http to match the default service discovery behavior (https+http://),\n            // where https is tried first.\n            endpoint = GetEndpointOrDefault(resourceWithEndpoints, \"https\", networkIdentifier) ?? GetEndpointOrDefault(resourceWithEndpoints, \"http\", networkIdentifier);\n        }\n\n        if (endpoint is null)\n        {\n            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.EndpointForResourceNotFoundExceptionMessage, endpointName, resourceName), nameof(endpointName));\n        }","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Testing/DistributedApplicationHostingTestingExtensions.cs#L252-L288","documentation":"GetEndpointUriStringCore throws this ArgumentException when the resolved resource does not implement IResourceWithEndpoints, meaning no endpoints have been (or can be) allocated for it. Despite the message text, the immediate condition is a type mismatch: the resource cannot expose endpoint references at all.","triggerScenarios":"Calling app.GetEndpoint(\"projectName\") (or GetEndpointUriStringCore via GetEndpointForNetwork) on a resource that is not a project/executable/container with endpoint annotations — e.g. a database or parameter resource.","commonSituations":"Passing a database/queue resource name to GetEndpoint instead of a web project; custom resource types lacking EndpointAnnotation; misremembering which resource owns the HTTP endpoint.","solutions":["Call GetEndpoint on the project or container resource that declares endpoints (e.g. the web frontend)","Add an endpoint to the resource in the AppHost (WithEndpoint/WithHttpEndpoint) if it should expose one","Check resource type with app.GetResource(name) before requesting an endpoint"],"exampleFix":"// before\nvar url = app.GetEndpoint(\"postgres\"); // no endpoints\n// after\nvar url = app.GetEndpoint(\"frontend\", \"https\");","handlingStrategy":"type-guard","validationCode":"var resource = app.GetResource(name);\nbool hasEndpoints = resource is IResourceWithEndpoints;","typeGuard":"static bool HasEndpoints(DistributedApplication app, string name) =>\n    app.GetResource(name) is IResourceWithEndpoints;","tryCatchPattern":"try { var url = app.GetEndpoint(name); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"endpoints\"))\n{\n    // resource cannot expose endpoints; target the right resource\n}","preventionTips":["Only request endpoints from project/container/executable resources","Add WithHttpEndpoint in the AppHost when an endpoint is needed","Verify the resource type before calling GetEndpoint"],"tags":["aspire","testing","endpoints","argument"],"backgroundTag":"invalid-argument-value","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"}