microsoft/aspire · error · InvalidOperationException
The container registry configured for the Azure sandbox…
Error message
The container registry configured for the Azure sandbox group '{Name}' is not an Azure Container Registry. Only Azure Container Registry resources are supported. Use '.WithAzureContainerRegistry()' to configure an Azure Container Registry. What it means
Thrown when constructing or initializing an AzureSandboxGroupResource whose configured container registry is present but is not an AzureContainerRegistryResource. Only Azure Container Registry is supported for sandbox image deployment; any other registry resource type is rejected with guidance to use .WithAzureContainerRegistry().
Solutions
- Replace the registry configuration with .WithAzureContainerRegistry() on the Azure sandbox group resource.
- Remove the non-Azure registry resource from the sandbox group configuration.
- Provision an Azure Container Registry resource and attach it via the sandbox-specific API.
- Check for extension methods like WithContainerRegistry in your AppHost and switch them to the sandbox-supported equivalent.
Example fix
// before sandboxGroup.WithContainerRegistry(registryResource); // after sandboxGroup.WithAzureContainerRegistry();
Defensive patterns
Strategy: validation
Validate before calling
bool IsAzureContainerRegistry(IResource? registry) => registry is AzureContainerRegistryResource;
Type guard
bool IsAcr(IResource? r) => r is AzureContainerRegistryResource;
Try / catch
try { builder.AddAzureSandboxGroup("sandbox"); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Azure Container Registry")) { /* reconfigure registry and retry */ } Prevention
- Always use .WithAzureContainerRegistry() for sandbox groups.
- Do not attach generic or third-party registry resources to sandbox groups.
- Review AppHost registry wiring when migrating from non-sandbox samples.
When it happens
Trigger: Adding a generic container registry resource (e.g. a plain ContainerRegistryResource or third-party registry resource) to an AzureSandboxGroupResource; the check `registry is not AzureContainerRegistryResource azureRegistry` fails and throws.
Common situations: Using .WithContainerRegistry() or a Docker Hub / generic registry extension instead of .WithAzureContainerRegistry(); upgrading from an older pattern that configured a raw registry resource; copy-pasting registry wiring from a non-sandbox sample.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Endpoint ' ' on resource ' ' is not exposed by the Azure…
- A BlobServiceClient could not be configured. Ensure valid…
- A BlobServiceClient could not be configured. Ensure valid…
- A ChatCompletionsClient could not be configured. Ensure…
- A CosmosClient could not be configured. Ensure valid…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/407d9cd05d9a0fc4.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxGroupResource.cs:152
IAzureContainerRegistryResource? IAzureComputeEnvironmentResource.ContainerRegistry => ContainerRegistry;
/// <summary>
/// Gets the Azure Container Registry resource used by this sandbox group.
/// </summary>
public AzureContainerRegistryResource? ContainerRegistry
{
get
{
var registry = GetContainerRegistry();
if (registry is null)
{
return null;
}
if (registry is not AzureContainerRegistryResource azureRegistry)
{
throw new InvalidOperationException(
$"The container registry configured for the Azure sandbox group '{Name}' is not an Azure Container Registry. " +
$"Only Azure Container Registry resources are supported. Use '.WithAzureContainerRegistry()' to configure an Azure Container Registry.");
}
return azureRegistry;
}
}
internal static string GetDashboardUrl(string subscriptionId, string resourceGroupName, string sandboxGroupName)
{
return $"{DashboardBaseUrl}/sandbox-groups/{Uri.EscapeDataString(subscriptionId)}/{Uri.EscapeDataString(resourceGroupName)}/{Uri.EscapeDataString(sandboxGroupName)}";
}
private async Task AddDashboardToPipelineSummaryAsync(PipelineStepContext context)
{
if (this.IsExcludedFromPublish())
{
return;View on GitHub (pinned to 25830f84bd)