microsoft/aspire · error · InvalidOperationException
Azure sandbox deployment state for resource
Error message
Azure sandbox deployment state for resource '{_resource.TargetResource.Name}' endpoint '{_endpointReferenceExpression.Endpoint.EndpointName}' contains invalid URL '{url}'. What it means
Thrown by GetValueFromUrl when the URL stored in the sandbox deployment state for an endpoint cannot be parsed as an absolute URI or has an empty host. The provider maps endpoint properties (host, port, scheme, etc.) onto this URL and rejects anything unparseable.
Solutions
- Re-run the sandbox deployment so a valid absolute URL (e.g. https://<id>--8080.<region>.adcproxy.io/) is persisted in the Ports section.
- Inspect the deployment state's Ports array and fix or remove the malformed Url entry.
- Verify the URL includes scheme and host exactly as produced by the deployment (absolute URI required).
- If the state is stale, delete it and let the deployment regenerate it.
Example fix
// before
{ "Ports": [{ "Name": "http", "Port": 8080, "Url": "localhost:8080" }] }
// after
{ "Ports": [{ "Name": "http", "Port": 8080, "Url": "https://sbx123--8080.eastus.adcproxy.io/" }] } Defensive patterns
Strategy: validation
Validate before calling
bool IsValidAbsoluteUrl(string url) =>
Uri.TryCreate(url, UriKind.Absolute, out var u) && !string.IsNullOrWhiteSpace(u.Host); Try / catch
try { var host = await provider.GetValueAsync(); }
catch (InvalidOperationException ex) { logger.LogError(ex, "Invalid sandbox URL in state"); throw; } Prevention
- Never hand-edit persisted sandbox URLs in deployment state.
- Redeploy if state entries look truncated or placeholder-like.
- Validate the Ports section schema after each deployment.
When it happens
Trigger: GetValueAsync reading a persisted Ports entry whose Url string is malformed (relative, empty, or missing host) and passing it to GetValueFromUrl; Uri.TryCreate fails or uri.Host is whitespace.
Common situations: Deployment state hand-edited with an invalid URL; an older/partial deployment wrote a placeholder URL; the ADC proxy URL was truncated when persisted.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- AppHost:DeploymentStatePathSha256 is required to isolate…
- Azure sandbox endpoint
- Azure sandbox group ' ' returned an invalid resource ID ' '.
- Deployment state section
- Endpoint ' ' on resource ' ' uses transport ' '. Azure…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/5b27b0f5cf96f24b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxEndpointPropertyValueProvider.cs:101
private string? GetKnownValueWithoutDeploymentState()
{
return _endpointReferenceExpression.Property switch
{
EndpointProperty.TargetPort => _targetPort.ToString(CultureInfo.InvariantCulture),
EndpointProperty.Scheme => Uri.UriSchemeHttps,
EndpointProperty.Port => "443",
EndpointProperty.TlsEnabled => bool.TrueString,
_ => null
};
}
private string GetValueFromUrl(string url)
{
if (!Uri.TryCreate(url, UriKind.Absolute, out var uri) ||
string.IsNullOrWhiteSpace(uri.Host))
{
throw new InvalidOperationException($"Azure sandbox deployment state for resource '{_resource.TargetResource.Name}' endpoint '{_endpointReferenceExpression.Endpoint.EndpointName}' contains invalid URL '{url}'.");
}
return _endpointReferenceExpression.Property switch
{
EndpointProperty.Url => url,
EndpointProperty.Host or EndpointProperty.IPV4Host => uri.Host,
EndpointProperty.Port => uri.Port.ToString(CultureInfo.InvariantCulture),
EndpointProperty.TargetPort => _targetPort.ToString(CultureInfo.InvariantCulture),
EndpointProperty.Scheme => uri.Scheme,
EndpointProperty.HostAndPort => uri.IsDefaultPort ? uri.Host : uri.Authority,
EndpointProperty.TlsEnabled => string.Equals(uri.Scheme, Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase) ? bool.TrueString : bool.FalseString,
_ => throw new InvalidOperationException($"The property '{_endpointReferenceExpression.Property}' is not supported for the endpoint '{_endpointReferenceExpression.Endpoint.EndpointName}'.")
};
}
private InvalidOperationException CreateUnresolvedEndpointException() =>
new($"Azure sandbox endpoint '{_endpointReferenceExpression.Endpoint.EndpointName}' on resource '{_resource.TargetResource.Name}' does not have a deployed URL yet. Runtime sandbox URLs cannot be used as first-pass Azure provisioning values; deploy the producing sandbox before resolving this reference.");
View on GitHub (pinned to 25830f84bd)