microsoft/aspire · error · InvalidOperationException

Resource ' ' does not have a compute environment. Ensure a…

Error message

Resource '{resource.Name}' does not have a compute environment. Ensure a compute environment (e.g., Azure Container Apps, Azure App Service) is configured in the application model.

What it means

Aspire's Azure Front Door integration requires every origin resource to belong to a compute environment (such as Azure Container Apps or Azure App Service), which is discovered via ComputeEnvironmentEndpointResolver. When GetEffectiveComputeEnvironment cannot find one on the resource (or its parents), it throws this InvalidOperationException during model finalization. The library needs the environment to place the origin correctly in the published Front Door topology.

Solutions

  1. Ensure the origin resource is hosted in a compute environment, e.g. add builder.AddContainerAppEnvironment(...) (Azure Container Apps) or an Azure App Service environment to the AppHost before publishing.
  2. Verify the resource passed as a Front Door origin is a project/container wired to that environment, not a bare resource.
  3. Check that the Azure provisioning packages (Aspire.Hosting.Azure.AppContainers / Azure.AppService) are referenced so environment annotations are created.

Example fix

// before
var frontDoor = builder.AddAzureFrontDoor("fd");
frontDoor.AddOrigin(builder.AddContainer("api", "image")); // no compute environment

// after
builder.AddContainerAppEnvironment("env");
var api = builder.AddContainer("api", "image"); // participates in the ACA environment
var frontDoor = builder.AddAzureFrontDoor("fd");
frontDoor.AddOrigin(api);
Defensive patterns

Strategy: validation

Validate before calling

var hasEnv = resource.Annotations.OfType<Microsoft.Extensions.Logging.ILoggerAnnotation>().Any() || ComputeEnvironmentEndpointResolver.TryGetEffectiveComputeEnvironment(resource, out _); // check before AddOrigin; simpler: only add resources created via AddProject/AddContainer in an AppHost that called AddContainerAppEnvironment

Type guard

static bool HasComputeEnvironment(IResource resource) => ComputeEnvironmentEndpointResolver.TryGetEffectiveComputeEnvironment(resource, out _);

Try / catch

try { frontDoor.AddOrigin(resource); } catch (InvalidOperationException ex) when (ex.Message.Contains("compute environment")) { /* configure ACA environment and retry model construction */ }

Prevention

When it happens

Trigger: Calling AddFrontDoor/addFrontDoor origin APIs with a resource (e.g., a project or container) that never had a compute environment attached, e.g. a plain container or executable resource without WithComputeEnvironment/Azure hosting environment wiring.

Common situations: Adding a backend project to Front Door in an app that only configures containers without a Container App environment; migrating an AppHost from plain run-mode resources to publish mode; forgetting to add the ACA/Azure App Service hosting extension that attaches the environment annotation.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting.Azure.FrontDoor/AzureFrontDoorExtensions.cs:214

            .OfType<AzureFrontDoorOriginAnnotation>()
            .Any(a => a.Resource.Name == resource.Resource.Name))
        {
            throw new InvalidOperationException(
                $"Origin resource '{resource.Resource.Name}' has already been added to Azure Front Door resource '{builder.Resource.Name}'. " +
                "Each origin can only be added once.");
        }

        return builder.WithAnnotation(new AzureFrontDoorOriginAnnotation(resource.Resource));
    }

    private static IComputeEnvironmentResource GetEffectiveComputeEnvironment(IResource resource)
    {
        if (ComputeEnvironmentEndpointResolver.TryGetEffectiveComputeEnvironment(resource, out var computeEnvironment))
        {
            return computeEnvironment;
        }

        throw new InvalidOperationException(
            $"Resource '{resource.Name}' does not have a compute environment. " +
            "Ensure a compute environment (e.g., Azure Container Apps, Azure App Service) is configured in the application model.");
    }

    private static EndpointReference GetOriginEndpoint(IResourceWithEndpoints resource)
    {
        var externalHttpEndpoint = resource.GetEndpoints()
            .Where(e => e.EndpointAnnotation.UriScheme is "http" or "https")
            .FirstOrDefault(e => e.EndpointAnnotation.IsExternal);

        if (externalHttpEndpoint is not null)
        {
            return externalHttpEndpoint;
        }

        throw new InvalidOperationException(
            $"Resource '{resource.Name}' does not have an external HTTP or HTTPS endpoint. " +
            "Azure Front Door requires an origin to expose an external HTTP or HTTPS endpoint. " +

View on GitHub (pinned to 25830f84bd)