{"record":{"id":"de8ee85659194b6d","repo":"microsoft/aspire","slug":"the-endpoint-endpointname-is-not-defined-for-the-resource","errorCode":null,"errorMessage":"The endpoint `{EndpointName}` is not defined for the resource `{Resource.Name}`. The resource has no endpoints defined.","messagePattern":"The endpoint `(.+?)` is not defined for the resource `(.+?)`\\. The resource has no endpoints defined\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/ApplicationModel/EndpointReference.cs","lineNumber":24,"sourceCode":"\nnamespace Aspire.Hosting.ApplicationModel;\n\n/// <summary>\n/// Represents an endpoint reference for a resource with endpoints.\n/// </summary>\n[AspireExport(ExposeProperties = true, ExposeMethods = true)]\n[DebuggerDisplay(\"Resource = {Resource.Name}, EndpointName = {EndpointName}, IsAllocated = {IsAllocated}\")]\npublic sealed class EndpointReference : IExpressionValue, IManifestExpressionProvider, IValueProvider, IValueWithReferences\n{\n    // A reference to the endpoint annotation if it exists.\n    private EndpointAnnotation? _endpointAnnotation;\n    private bool? _isAllocated;\n    private readonly NetworkIdentifier? _contextNetworkId;\n\n    /// <summary>\n    /// Gets the endpoint annotation associated with the endpoint reference.\n    /// </summary>\n    public EndpointAnnotation EndpointAnnotation => GetEndpointAnnotation() ?? throw new InvalidOperationException(ErrorMessage ?? BuildMissingEndpointMessage());\n\n    private string BuildMissingEndpointMessage()\n    {\n        var availableNames = Resource.Annotations\n            .OfType<EndpointAnnotation>()\n            .Select(a => a.Name)\n            .Where(n => !string.IsNullOrEmpty(n))\n            .Distinct(StringComparers.EndpointAnnotationName)\n            .ToArray();\n\n        if (availableNames.Length == 0)\n        {\n            return $\"The endpoint `{EndpointName}` is not defined for the resource `{Resource.Name}`. The resource has no endpoints defined.\";\n        }\n\n        var formattedNames = string.Join(\", \", availableNames.Select(static n => $\"`{n}`\"));\n        return $\"The endpoint `{EndpointName}` is not defined for the resource `{Resource.Name}`. Available endpoints: {formattedNames}.\";\n    }","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ApplicationModel/EndpointReference.cs#L6-L42","documentation":"EndpointReference resolves its EndpointAnnotation by name from the owning resource. When the resource has no endpoint annotations at all, accessing the property throws this InvalidOperationException explaining the resource has no endpoints defined.","triggerScenarios":"Accessing EndpointReference.EndpointAnnotation (directly or via .Port/.Host/etc.) for an endpoint name that was never added because no WithEndpoint/AddEndpoint-style call registered any endpoint on the resource.","commonSituations":"Referencing endpoints like builder.CreateResourceBuilder(...).GetEndpoint(\"http\") before WithEndpoint(\"http\") was called; copy-pasted code referencing another resource's endpoint name; conditional endpoint registration skipped at runtime.","solutions":["Call .WithEndpoint(name, ...) (or AddEndpoint) on the resource to define the endpoint before referencing it","Verify the endpoint name spelling exactly matches the registered annotation (endpoint names are case-sensitive strings)","If the endpoint should come from a referenced resource, reference the correct resource's endpoint instead of building a new EndpointReference manually"],"exampleFix":"// before\nvar db = builder.AddPostgres(\"db\").AddDatabase(\"mydb\");\nvar port = db.Resource.GetEndpoint(\"http\").Port; // no 'http' endpoint exists\n// after\nvar db = builder.AddPostgres(\"db\").WithEndpoint(1432, 5432, \"http\");\nvar port = db.Resource.GetEndpoint(\"http\").Port;","handlingStrategy":"validation","validationCode":"bool hasEndpoint = resource.Annotations.OfType<EndpointAnnotation>().Any(a => a.Name == \"http\");\nif (!hasEndpoint) throw new ArgumentException(\"Resource has no 'http' endpoint.\");","typeGuard":"bool TryGetEndpoint(IResource resource, string name, out EndpointAnnotation? endpoint) {\n  endpoint = resource.Annotations.OfType<EndpointAnnotation>().FirstOrDefault(a => string.Equals(a.Name, name, StringComparison.Ordinal));\n  return endpoint is not null;\n}","tryCatchPattern":"try { var port = endpointRef.Port; } catch (InvalidOperationException ex) when (ex.Message.Contains(\"is not defined for the resource\")) { /* fall back or report config error */ }","preventionTips":["Always pair GetEndpoint(name) with a preceding WithEndpoint(name, ...) call","Keep endpoint names in constants shared between registration and reference","Use the resource builder's typed endpoint helpers instead of raw string names when available"],"tags":["aspire","endpoints","configuration"],"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"}