{"record":{"id":"89bd395335c16bf4","repo":"microsoft/aspire","slug":"browsermessagestrings-browserlogsendpointnotallocated","errorCode":null,"errorMessage":"BrowserMessageStrings.BrowserLogsEndpointNotAllocated","messagePattern":"BrowserMessageStrings\\.BrowserLogsEndpointNotAllocated","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Browsers/BrowserLogsBuilderExtensions.cs","lineNumber":336,"sourceCode":"\n        static Uri ResolveBrowserUrl(T resource)\n        {\n            EndpointAnnotation? endpointAnnotation = null;\n            if (resource.TryGetAnnotationsOfType<EndpointAnnotation>(out var endpoints))\n            {\n                endpointAnnotation = endpoints.FirstOrDefault(e => e.UriScheme == \"https\")\n                    ?? endpoints.FirstOrDefault(e => e.UriScheme == \"http\");\n            }\n\n            if (endpointAnnotation is null)\n            {\n                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, BrowserMessageStrings.BrowserLogsResourceMissingHttpEndpoint, resource.Name));\n            }\n\n            var endpointReference = resource.GetEndpoint(endpointAnnotation.Name);\n            if (!endpointReference.IsAllocated)\n            {\n                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, BrowserMessageStrings.BrowserLogsEndpointNotAllocated, endpointAnnotation.Name, resource.Name));\n            }\n\n            return new Uri(endpointReference.Url, UriKind.Absolute);\n        }\n\n        static void ThrowIfBlankWhenSpecified(string? value, string paramName)\n        {\n            if (value is not null)\n            {\n                ArgumentException.ThrowIfNullOrWhiteSpace(value, paramName);\n            }\n        }\n    }\n\n    private sealed record BrowserLogsScreenshotCommandResult(\n        string ResourceName,\n        string SessionId,\n        string Browser,","sourceCodeStart":318,"sourceCodeEnd":354,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Browsers/BrowserLogsBuilderExtensions.cs#L318-L354","documentation":"The resource has an http/https endpoint annotation, but the endpoint reference is not yet allocated — no port has been assigned, so endpointReference.Url cannot produce an absolute URL. Aspire allocates endpoint ports when the app model transitions to run mode, so reading the URL too early throws.","triggerScenarios":"Resolving the endpoint URL during model building/publish mode, or via a callback executed before port allocation; calling code that reads GetEndpoint(...).Url while IsAllocated is still false.","commonSituations":"Publish-mode evaluation of WithBrowserLogs callbacks; inspecting endpoint URLs in tests before the AppHost starts; custom code reading endpoint URLs during OnBuildingResource instead of after allocation.","solutions":["Defer URL resolution to a point after allocation (use callbacks evaluated at run/start time).","Run the AppHost in run mode, where ports are allocated at startup.","Check endpointReference.IsAllocated before reading Url and handle the not-yet-allocated case."],"exampleFix":"// before\nvar url = resource.GetEndpoint(\"http\").Url; // throws when not allocated\n\n// after\nvar endpoint = resource.GetEndpoint(\"http\");\nif (!endpoint.IsAllocated) return; // or defer until AfterEndpointsAllocatedEvent\nvar url = endpoint.Url;","handlingStrategy":"validation","validationCode":"// Only read the URL after the endpoint is allocated\nvar endpoint = resource.GetEndpoint(\"http\");\nif (!endpoint.IsAllocated) throw new InvalidOperationException(\"Endpoint not yet allocated; defer URL resolution until after startup.\");\nvar url = endpoint.Url;","typeGuard":null,"tryCatchPattern":"try { var url = endpoint.Url; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"allocat\", StringComparison.OrdinalIgnoreCase)) { logger.LogWarning(ex, \"Endpoint {Name} not allocated yet; resolve after startup.\", endpoint.EndpointName); }","preventionTips":["Resolve endpoint URLs in run-mode lifecycle events (e.g. AfterEndpointsAllocatedEvent), never at build time.","Check EndpointReference.IsAllocated before touching Url.","Do not read endpoint URLs in publish-mode code paths."],"tags":["endpoint","port-allocation","lifecycle","aspire-hosting"],"backgroundTag":"endpoint-not-allocated","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"}