{"record":{"id":"3f59a1b90f8930fd","repo":"microsoft/aspire","slug":"cannot-create-a-microsoft-foundry-project-connection-to-an-3f59a1","errorCode":null,"errorMessage":"Cannot create a Microsoft Foundry project connection to an emulator Container Registry","messagePattern":"Cannot create a Microsoft Foundry project connection to an emulator Container Registry","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Foundry/Project/ConnectionBuilderExtensions.cs","lineNumber":177,"sourceCode":"    {\n        builder.WithRoleAssignments(storage, StorageBuiltInRole.StorageBlobDataContributor);\n        return builder.AddConnection(storage.Resource);\n    }\n\n    /// <summary>\n    /// Adds a container registry connection to the Microsoft Foundry project.\n    /// </summary>\n    /// <returns></returns>\n    [AspireExportIgnore(Reason = \"Raw AzureContainerRegistryResource parameters are not ATS-compatible. Use the resource-builder overload instead.\")]\n    public static IResourceBuilder<AzureCognitiveServicesProjectConnectionResource> AddConnection(\n        this IResourceBuilder<AzureCognitiveServicesProjectResource> builder,\n        AzureContainerRegistryResource registry)\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n        ArgumentNullException.ThrowIfNull(registry);\n        if (registry.IsEmulator())\n        {\n            throw new InvalidOperationException(\"Cannot create a Microsoft Foundry project connection to an emulator Container Registry\");\n        }\n        return builder.AddConnection($\"connection-{Guid.NewGuid():N}\", (infra) => new ManagedIdentityAuthTypeConnectionProperties()\n        {\n            Category = CognitiveServicesConnectionCategory.ContainerRegistry,\n            Target = registry.RegistryEndpoint.AsProvisioningParameter(infra),\n            IsSharedToAll = true,\n            Credentials = new CognitiveServicesConnectionManagedIdentity(){\n                ClientId = \"aiprojectidentityprincipleaid\",\n                ResourceId = registry.NameOutputReference.AsProvisioningParameter(infra)\n            },\n            Metadata =\n            {\n                { \"ApiType\", \"Azure\" },\n                { \"ResourceId\", registry.NameOutputReference.AsProvisioningParameter(infra) }\n            }\n        });\n    }\n","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Foundry/Project/ConnectionBuilderExtensions.cs#L159-L195","documentation":"Foundry project connections to a container registry need an actual Azure Container Registry endpoint. AddConnection for Container Registry throws this InvalidOperationException when the supplied AzureContainerRegistryResource runs as an emulator, which Foundry cannot use as a connection target.","triggerScenarios":"Calling foundryProject.AddConnection(registry) where the AzureContainerRegistryResource builder had RunAsEmulator() applied (registry.IsEmulator() returns true).","commonSituations":"Local test configurations emulating ACR; reusing a shared emulated registry resource across the app model while wiring Foundry connections.","solutions":["Remove RunAsEmulator() from the Container Registry resource.","Guard the connection call so it only runs for non-emulated registry resources.","Provision a real Azure Container Registry for the Foundry project connection."],"exampleFix":"// before\nvar registry = builder.AddAzureContainerRegistry(\"acr\").RunAsEmulator();\nproject.AddConnection(registry); // throws\n\n// after\nvar registry = builder.AddAzureContainerRegistry(\"acr\");\nproject.AddConnection(registry);","handlingStrategy":"validation","validationCode":"if (!registry.IsEmulator())\n    project.AddConnection(registry);","typeGuard":null,"tryCatchPattern":"try { project.AddConnection(registry); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"emulator Container Registry\")) { /* skip or provision real ACR */ }","preventionTips":["Check registry.IsEmulator() before wiring the connection.","Do not emulate a registry that the Foundry project must connect to.","Centralize emulator decisions in one place so connection wiring can consult them."],"tags":["azure-ai-foundry","container-registry","emulator","connection"],"backgroundTag":"unsupported-operation","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"}