{"record":{"id":"0bb1f790c1868017","repo":"microsoft/aspire","slug":"resource-resource-name-is-configured-to-publish-as-an-azure-0bb1f7","errorCode":null,"errorMessage":"Resource '{resource.Name}' is configured to publish as an Azure sandbox, but it is assigned to compute environment '{computeEnvironment.Name}', which is not an active Azure sandbox group. Assign it to an 'AzureSandboxGroupResource' by calling 'WithComputeEnvironment'.","messagePattern":"Resource '(.+?)' is configured to publish as an Azure sandbox, but it is assigned to compute environment '(.+?)', which is not an active Azure sandbox group\\. Assign it to an 'AzureSandboxGroupResource' by calling 'WithComputeEnvironment'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxesExtensions.cs","lineNumber":491,"sourceCode":"                {\n                    if (!resource.HasAnnotationOfType<AzureSandboxContainerOptionsAnnotation>())\n                    {\n                        continue;\n                    }\n\n                    if (sandboxGroups.Count == 0)\n                    {\n                        throw new InvalidOperationException(\n                            $\"Resource '{resource.Name}' is configured to publish as an Azure sandbox, but there are no '{nameof(AzureSandboxGroupResource)}' resources. \" +\n                            $\"Ensure you have added one by calling '{nameof(AddAzureSandboxGroup)}'.\");\n                    }\n\n                    var computeEnvironment = resource.GetComputeEnvironment();\n                    if (computeEnvironment is not null &&\n                        (computeEnvironment is not AzureSandboxGroupResource sandboxGroup ||\n                         !sandboxGroups.Contains(sandboxGroup)))\n                    {\n                        throw new InvalidOperationException(\n                            $\"Resource '{resource.Name}' is configured to publish as an Azure sandbox, but it is assigned to compute environment '{computeEnvironment.Name}', which is not an active Azure sandbox group. \" +\n                            $\"Assign it to an '{nameof(AzureSandboxGroupResource)}' by calling 'WithComputeEnvironment'.\");\n                    }\n                }\n\n                return Task.CompletedTask;\n            },\n            dependsOn: WellKnownPipelineSteps.ValidateComputeEnvironments,\n            requiredBy: WellKnownPipelineSteps.BeforeStart);\n    }\n\n    private static void ApplyManagedServiceIdentity(\n        ManagedServiceIdentity identity,\n        AzureSandboxGroupResource resource,\n        BicepValue<string> imagePullIdentityId,\n        AzureResourceInfrastructure infrastructure)\n    {\n        identity.ManagedServiceIdentityType = resource.WorkloadManagedIdentityType switch","sourceCodeStart":473,"sourceCodeEnd":509,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxesExtensions.cs#L473-L509","documentation":"A resource published with PublishAsAzureSandbox must be assigned to an AzureSandboxGroupResource that is part of the active sandbox groups. If the resource's compute environment is some other environment type, or a sandbox group not present in the current model, publish validation throws this InvalidOperationException and suggests assigning it with WithComputeEnvironment.","triggerScenarios":"resource.WithComputeEnvironment(environment) called with a non-sandbox compute environment (e.g. an Azure environment resource), or with a sandbox group that was not added/active in the model, while PublishAsAzureSandbox is applied to the resource.","commonSituations":"Mixing sandbox publishing with a regular Azure compute environment from another integration; pointing at a sandbox group defined in a different branch/condition so it is not in the active set; renaming or removing the group but leaving stale WithComputeEnvironment wiring.","solutions":["Call WithComputeEnvironment with the AzureSandboxGroupResource returned by AddAzureSandboxGroup","Verify the referenced group is actually added in the AppHost (not conditionally skipped)","Remove the non-sandbox compute environment assignment that conflicts with sandbox publishing"],"exampleFix":"// before\nvar env = builder.AddAzureEnvironment(\"env\");\nbuilder.AddProject<Projects.Frontend>(\"frontend\").PublishAsAzureSandbox().WithComputeEnvironment(env);\n// after\nvar group = builder.AddAzureSandboxGroup(\"sandbox-group\");\nbuilder.AddProject<Projects.Frontend>(\"frontend\").PublishAsAzureSandbox().WithComputeEnvironment(group);","handlingStrategy":"validation","validationCode":"var env = resource.GetComputeEnvironment();\nif (env is not null && env is not AzureSandboxGroupResource) throw new InvalidOperationException(\"Assign an AzureSandboxGroupResource via WithComputeEnvironment\");","typeGuard":null,"tryCatchPattern":"try { app.Run(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"WithComputeEnvironment\")) { /* fix compute environment assignment */ }","preventionTips":["Always pass the AddAzureSandboxGroup return value to WithComputeEnvironment","Don't mix regular Azure compute environments with sandbox publishing on the same resource","Verify the referenced group exists unconditionally in the AppHost"],"tags":["azure-sandbox","publish","compute-environment","configuration"],"backgroundTag":"invalid-state-transition","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}