{"record":{"id":"1c669868daa2f404","repo":"microsoft/aspire","slug":"the-container-registry-configured-for-the-azure-cognitive","errorCode":null,"errorMessage":"The container registry configured for the Azure Cognitive Services project '{Name}' is not an Azure Container Registry. Only Azure Container Registry resources are supported. Use '.WithAzureContainerRegistry()' to configure an Azure Container Registry.","messagePattern":"The container registry configured for the Azure Cognitive Services project '(.+?)' is not an Azure Container Registry\\. Only Azure Container Registry resources are supported\\. Use '\\.WithAzureContainerRegistry\\(\\)' to configure an Azure Container Registry\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Foundry/Project/ProjectResource.cs","lineNumber":170,"sourceCode":"    IAzureContainerRegistryResource? IAzureComputeEnvironmentResource.ContainerRegistry => ContainerRegistry;\n\n    /// <summary>\n    /// Gets the Azure Container Registry resource used by this project.\n    /// </summary>\n    public AzureContainerRegistryResource? ContainerRegistry\n    {\n        get\n        {\n            var registry = GetContainerRegistry();\n\n            if (registry is null)\n            {\n                return null;\n            }\n\n            if (registry is not AzureContainerRegistryResource azureRegistry)\n            {\n                throw new InvalidOperationException(\n                    $\"The container registry configured for the Azure Cognitive Services project '{Name}' is not an Azure Container Registry. \" +\n                    $\"Only Azure Container Registry resources are supported. Use '.WithAzureContainerRegistry()' to configure an Azure Container Registry.\");\n            }\n\n            return azureRegistry;\n        }\n    }\n\n    private IContainerRegistry? GetContainerRegistry()\n    {\n        if (this.TryGetLastAnnotation<ContainerRegistryReferenceAnnotation>(out var annotation))\n        {\n            return annotation.Registry;\n        }\n        return DefaultContainerRegistry;\n    }\n\n    /// <summary>","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Foundry/Project/ProjectResource.cs#L152-L188","documentation":"A Foundry project's container registry must be an AzureContainerRegistryResource. When the configured registry is some other resource type, the internal registry property getter throws this InvalidOperationException and points at WithAzureContainerRegistry() as the correct configuration API.","triggerScenarios":"Assigning a generic container registry / non-ACR registry resource to the project's registry property, then accessing the typed AzureContainerRegistryResource property (e.g. during infrastructure generation).","commonSituations":"Using a Docker/other registry resource or a plain ConnectionString resource where an ACR resource is expected; older code configured before the ACR-only requirement; passing the wrong builder to the registry-assigning API.","solutions":["Use .WithAzureContainerRegistry(azureContainerRegistryBuilder) with an AddAzureContainerRegistry-created resource","Remove or replace the non-ACR registry assignment on the project","Verify the resource type is AzureContainerRegistryResource before assigning it"],"exampleFix":"// before\nproject.WithContainerRegistry(myGenericRegistry);\n\n// after\nvar acr = builder.AddAzureContainerRegistry(\"acr\");\nproject.WithAzureContainerRegistry(acr);","handlingStrategy":"type-guard","validationCode":"if (registry is not AzureContainerRegistryResource)\n{\n    throw new InvalidOperationException(\"Only Azure Container Registry resources are supported.\");\n}\nproject.WithAzureContainerRegistry(registry);","typeGuard":"static bool IsAzureContainerRegistry(IResource r) => r is AzureContainerRegistryResource;","tryCatchPattern":"try { /* access project registry / publish */ }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"not an Azure Container Registry\"))\n{\n    // Reconfigure with AddAzureContainerRegistry.\n}","preventionTips":["Create registries with AddAzureContainerRegistry for Foundry projects","Never assign generic or non-Azure registry resources","Type registry builders explicitly as IResourceBuilder<AzureContainerRegistryResource>"],"tags":["csharp","aspire","azure","container-registry","type-mismatch"],"backgroundTag":"incompatible-source-type","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"}