{"record":{"id":"f6a5dba97c7e39f6","repo":"microsoft/aspire","slug":"no-container-registry-configured-for-azure-cognitive","errorCode":null,"errorMessage":"No container registry configured for Azure Cognitive Services project resource '{aspireResource.Name}'. A container registry is required to publish hosted agents.","messagePattern":"No container registry configured for Azure Cognitive Services project resource '(.+?)'\\. A container registry is required to publish hosted agents\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Foundry/Project/ProjectBuilderExtension.cs","lineNumber":440,"sourceCode":"         * Container registry for hosted agents\n         *\n         * Only provision registry dependencies when the project will publish a hosted agent\n         * or when the user has explicitly supplied a registry override.\n         */\n        if (RequiresContainerRegistryProvisioning(aspireResource))\n        {\n            AzureProvisioningResource? registry = null;\n            if (aspireResource.TryGetLastAnnotation<ContainerRegistryReferenceAnnotation>(out var registryReferenceAnnotation) && registryReferenceAnnotation.Registry is AzureProvisioningResource r)\n            {\n                registry = r;\n            }\n            else if (aspireResource.DefaultContainerRegistry is not null)\n            {\n                registry = aspireResource.DefaultContainerRegistry;\n            }\n            else\n            {\n                throw new InvalidOperationException($\"No container registry configured for Azure Cognitive Services project resource '{aspireResource.Name}'. A container registry is required to publish hosted agents.\");\n            }\n\n            var containerRegistry = (ContainerRegistryService)registry.AddAsExistingResource(infra);\n            infra.Add(containerRegistry);\n\n            // Project needs this to pull hosted agent images during hosted-agent deployment.\n            var pullRa = containerRegistry.CreateRoleAssignment(ContainerRegistryBuiltInRole.AcrPull, RoleManagementPrincipalType.ServicePrincipal, projectPrincipalId);\n            // There's a bug in the CDK, see https://github.com/Azure/azure-sdk-for-net/issues/47265\n            pullRa.Name = BicepFunction.CreateGuid(containerRegistry.Id, project.Id, pullRa.RoleDefinitionId);\n            infra.Add(pullRa);\n            infra.Add(containerRegistry);\n            infra.Add(new ProvisioningOutput(\"AZURE_CONTAINER_REGISTRY_ENDPOINT\", typeof(string))\n            {\n                Value = containerRegistry.LoginServer\n            });\n            infra.Add(new ProvisioningOutput(\"AZURE_CONTAINER_REGISTRY_NAME\", typeof(string))\n            {\n                Value = containerRegistry.Name","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Foundry/Project/ProjectBuilderExtension.cs#L422-L458","documentation":"When publishing (generating infrastructure for) hosted agents on a Foundry project, the project must know which container registry to pull agent images from. If neither an explicitly assigned registry nor a DefaultContainerRegistry is set, ConfigureInfrastructure throws this InvalidOperationException.","triggerScenarios":"Running aspire publish / deploy-mode infrastructure generation for a Foundry project with hosted agents where no container registry was attached via WithAzureContainerRegistry (or equivalent) and no default registry exists on the resource.","commonSituations":"Running locally fine (no publish path) but failing on publish; forgetting to configure a registry in CI where the AppHost publishes hosted agents; a shared AppHost used across environments where only some set a registry.","solutions":["Call .WithAzureContainerRegistry(registryBuilder) on the Foundry project resource before publishing","Ensure a DefaultContainerRegistry is set on the project resource (e.g. via a shared publish callback)","Verify the publish path is taken only after registry configuration runs (ordering of builder calls)"],"exampleFix":"// before\nvar project = foundry.AddProject(\"agents\");\n\n// after\nvar project = foundry.AddProject(\"agents\").WithAzureContainerRegistry(containerRegistry);","handlingStrategy":"validation","validationCode":"if (publishingHostedAgents && project.Resource.DefaultContainerRegistry is null)\n{\n    project.WithAzureContainerRegistry(containerRegistry);\n}","typeGuard":null,"tryCatchPattern":"try { /* publish / run in publish mode */ }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"No container registry configured\"))\n{\n    // Configure an ACR and re-run publish.\n}","preventionTips":["Always attach an Azure Container Registry to Foundry projects that publish hosted agents","Verify publish-mode runs in CI so missing registry config fails early","Set the registry in the same builder chain as the project resource"],"tags":["csharp","aspire","azure","publish","missing-config"],"backgroundTag":"missing-required-config","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"}