microsoft/aspire · error · InvalidOperationException
BrowserMessageStrings.BrowserLogsEndpointNotAllocated
Error message
BrowserMessageStrings.BrowserLogsEndpointNotAllocated
What it means
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.
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.
Example fix
// before
var url = resource.GetEndpoint("http").Url; // throws when not allocated
// after
var endpoint = resource.GetEndpoint("http");
if (!endpoint.IsAllocated) return; // or defer until AfterEndpointsAllocatedEvent
var url = endpoint.Url; Defensive patterns
Strategy: validation
Validate before calling
// Only read the URL after the endpoint is allocated
var endpoint = resource.GetEndpoint("http");
if (!endpoint.IsAllocated) throw new InvalidOperationException("Endpoint not yet allocated; defer URL resolution until after startup.");
var url = endpoint.Url; Try / catch
try { var url = endpoint.Url; }
catch (InvalidOperationException ex) when (ex.Message.Contains("allocat", StringComparison.OrdinalIgnoreCase)) { logger.LogWarning(ex, "Endpoint {Name} not allocated yet; resolve after startup.", endpoint.EndpointName); } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- BrowserMessageStrings.BrowserLogsResourceMissingHttpEndpoint
- Could not create for resource ' ' as the endpoint with name…
- Could not create for resource ' ' as no endpoint was found…
- Could not create HTTP command for resource
- Endpoint is unavailable
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/89bd395335c16bf4.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Browsers/BrowserLogsBuilderExtensions.cs:336
static Uri ResolveBrowserUrl(T resource)
{
EndpointAnnotation? endpointAnnotation = null;
if (resource.TryGetAnnotationsOfType<EndpointAnnotation>(out var endpoints))
{
endpointAnnotation = endpoints.FirstOrDefault(e => e.UriScheme == "https")
?? endpoints.FirstOrDefault(e => e.UriScheme == "http");
}
if (endpointAnnotation is null)
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, BrowserMessageStrings.BrowserLogsResourceMissingHttpEndpoint, resource.Name));
}
var endpointReference = resource.GetEndpoint(endpointAnnotation.Name);
if (!endpointReference.IsAllocated)
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, BrowserMessageStrings.BrowserLogsEndpointNotAllocated, endpointAnnotation.Name, resource.Name));
}
return new Uri(endpointReference.Url, UriKind.Absolute);
}
static void ThrowIfBlankWhenSpecified(string? value, string paramName)
{
if (value is not null)
{
ArgumentException.ThrowIfNullOrWhiteSpace(value, paramName);
}
}
}
private sealed record BrowserLogsScreenshotCommandResult(
string ResourceName,
string SessionId,
string Browser,View on GitHub (pinned to 25830f84bd)