{"record":{"id":"3b0f19ba15e4b4cc","repo":"microsoft/aspire","slug":"resource-resource-name-is-configured-to-publish-as-an-azure","errorCode":null,"errorMessage":"Resource '{resource.Name}' is configured to publish as an Azure sandbox, but there are no 'AzureSandboxGroupResource' resources. Ensure you have added one by calling 'AddAzureSandboxGroup'.","messagePattern":"Resource '(.+?)' is configured to publish as an Azure sandbox, but there are no 'AzureSandboxGroupResource' resources\\. Ensure you have added one by calling 'AddAzureSandboxGroup'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxesExtensions.cs","lineNumber":481,"sourceCode":"                {\n                    return Task.CompletedTask;\n                }\n\n                var sandboxGroups = context.Model.Resources\n                    .OfType<AzureSandboxGroupResource>()\n                    .Where(static group => !group.IsExcludedFromPublish())\n                    .ToHashSet();\n\n                foreach (var resource in context.Model.GetComputeResources())\n                {\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,","sourceCodeStart":463,"sourceCodeEnd":499,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxesExtensions.cs#L463-L499","documentation":"During publish, EnsureSandboxPublisherValidationAdded verifies that a resource marked with PublishAsAzureSandbox actually has at least one AzureSandboxGroupResource in the application model. Sandbox publishing requires sandbox groups to host resources; with none defined, the publish model is incomplete and an InvalidOperationException is thrown.","triggerScenarios":"Calling resource.PublishAsAzureSandbox() but never calling AddAzureSandboxGroup anywhere in the AppHost, then running publish/start; all sandbox groups removed or filtered out so sandboxGroups.Count == 0 at validation time.","commonSituations":"Adding the PublishAsAzureSandbox call from a sample without the accompanying AddAzureSandboxGroup step; conditional code paths that add sandbox groups not taken at runtime; refactoring that deleted the group definition while leaving the publisher annotation.","solutions":["Add a sandbox group in the AppHost: builder.AddAzureSandboxGroup(\"group-name\")","Ensure the AddAzureSandboxGroup call is not behind a condition that is skipped at publish time","Remove PublishAsAzureSandbox if sandbox publishing was not intended"],"exampleFix":"// before\nbuilder.AddProject<Projects.Frontend>(\"frontend\").PublishAsAzureSandbox();\n// after\nvar group = builder.AddAzureSandboxGroup(\"sandbox-group\");\nbuilder.AddProject<Projects.Frontend>(\"frontend\").PublishAsAzureSandbox().WithComputeEnvironment(group);","handlingStrategy":"validation","validationCode":"// in AppHost, before building\nvar hasGroups = ((IDistributedApplicationBuilder)builder).Resources.OfType<AzureSandboxGroupResource>().Any();\nif (!hasGroups) throw new InvalidOperationException(\"PublishAsAzureSandbox requires AddAzureSandboxGroup\");","typeGuard":null,"tryCatchPattern":"try { app.Run(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"AddAzureSandboxGroup\")) { /* add sandbox group and re-run */ }","preventionTips":["Pair every PublishAsAzureSandbox call with AddAzureSandboxGroup in the same AppHost","Check conditional code paths that may skip group creation","Grep the AppHost for AddAzureSandboxGroup when adopting sandbox publishing"],"tags":["azure-sandbox","publish","missing-resource","configuration"],"backgroundTag":"missing-dependency","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}