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

  1. Replace the registry configuration with .WithAzureContainerRegistry() on the Azure sandbox group resource.
  2. Remove the non-Azure registry resource from the sandbox group configuration.
  3. Provision an Azure Container Registry resource and attach it via the sandbox-specific API.
  4. 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

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


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)