microsoft/aspire · error · NotSupportedException

Azure sandbox resource

Error message

Azure sandbox resource '{resource.TargetResource.Name}' in sandbox group '{resource.Parent.Name}' references resource '{dependency.Name}' in sandbox group '{producer.Parent.Name}', but cross-group sandbox references are not supported. Deploy both resources to the same sandbox group.

What it means

During sandbox deployment pipeline configuration, Aspire orders consumer steps to depend on producer steps that supply referenced values. If a sandbox resource references a value produced by a resource in a different sandbox group, the deploy ordering cannot be expressed within one group, so NotSupportedException is thrown. Cross-sandbox-group references are simply not supported.

Solutions

  1. Move the referencing resource and its dependency into the same sandbox group (set the same parent).
  2. If the resources must live in separate groups, break the direct reference and pass the value explicitly via configuration/connection strings rather than resource references.
  3. Consolidate the sandbox groups so all interdependent resources share one group.

Example fix

// before
var db = builder.AddAzureSandboxPostgres("db", sandboxGroupA);
var api = builder.AddAzureSandboxContainer("api", sandboxGroupB).WithReference(db);
// after
var api = builder.AddAzureSandboxContainer("api", sandboxGroupA).WithReference(db);
Defensive patterns

Strategy: validation

Validate before calling

// before deploy: assert every referenced producer is in the same sandbox group
foreach (var r in resources)
    foreach (var dep in r.References)
        if (!ReferenceEquals(dep.Parent, r.Parent))
            throw new InvalidOperationException($"{r.Name} references cross-group {dep.Name}");

Try / catch

try { await deployment.ConfigureDeployOrderingAsync(...); }
catch (NotSupportedException ex) { /* regroup resources into one sandbox group or pass values via config */ throw new InvalidOperationException(ex.Message, ex); }

Prevention

When it happens

Trigger: Deploying Azure sandbox resources where resource A in sandbox group G1 references an output/endpoint of resource B in sandbox group G2, so ConfigureDeployOrderingAsync detects producer.Parent != resource.Parent.

Common situations: Splitting an app's sandboxes across multiple sandbox groups (e.g. per-team or per-environment groups) while still wiring a container in one group to a database or service in another group.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/91269c9cf0c8fd93. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxContainerDeployment.cs:169

        if (resource.Parent.ContainerRegistry is { } registry)
        {
            deploySteps.DependsOn(context.GetSteps(registry, "acr-login"));
        }

        var executionContext = context.Services.GetRequiredService<DistributedApplicationExecutionContext>();
        var dependencies = await resource.TargetResource.GetResourceDependenciesAsync(
            executionContext,
            ResourceDependencyDiscoveryMode.DirectOnly).ConfigureAwait(false);
        foreach (var dependency in dependencies)
        {
            if (dependency.GetDeploymentTargetAnnotation()?.DeploymentTarget is not AzureSandboxContainerResource producer)
            {
                continue;
            }

            if (!ReferenceEquals(producer.Parent, resource.Parent))
            {
                throw new NotSupportedException(
                    $"Azure sandbox resource '{resource.TargetResource.Name}' in sandbox group '{resource.Parent.Name}' references resource '{dependency.Name}' in sandbox group '{producer.Parent.Name}', but cross-group sandbox references are not supported. Deploy both resources to the same sandbox group.");
            }

            var producerSteps = context.GetSteps(producer, WellKnownPipelineTags.DeployCompute);
            foreach (var consumerStep in deploySteps)
            {
                foreach (var producerStep in producerSteps)
                {
                    if (WouldCreateDependencyCycle(context.Steps, consumerStep, producerStep))
                    {
                        throw new InvalidOperationException(
                            $"Azure sandbox resources '{resource.TargetResource.Name}' and '{producer.TargetResource.Name}' have a circular deployment dependency.");
                    }

                    consumerStep.DependsOn(producerStep);
                }
            }
        }

View on GitHub (pinned to 25830f84bd)