{"record":{"id":"bfaf485121bbc6f6","repo":"microsoft/aspire","slug":"cannot-create-a-microsoft-foundry-project-connection-to-an-bfaf48","errorCode":null,"errorMessage":"Cannot create a Microsoft Foundry project connection to an emulator Storage account.","messagePattern":"Cannot create a Microsoft Foundry project connection to an emulator Storage account\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Foundry/Project/ConnectionBuilderExtensions.cs","lineNumber":137,"sourceCode":"        IResourceBuilder<AzureCosmosDBResource> db)\n    {\n        return builder.AddConnection(db.Resource);\n    }\n\n    /// <summary>\n    /// Adds an Azure Storage account to a project as a connection.\n    /// </summary>\n    /// <returns></returns>\n    [AspireExportIgnore(Reason = \"Raw AzureStorageResource parameters are not ATS-compatible. Use the resource-builder overload instead.\")]\n    public static IResourceBuilder<AzureCognitiveServicesProjectConnectionResource> AddConnection(\n        this IResourceBuilder<AzureCognitiveServicesProjectResource> builder,\n        AzureStorageResource storage)\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n        ArgumentNullException.ThrowIfNull(storage);\n        if (storage.IsEmulator())\n        {\n            throw new InvalidOperationException(\"Cannot create a Microsoft Foundry project connection to an emulator Storage account.\");\n        }\n        return builder.AddConnection($\"connection-{Guid.NewGuid():N}\", (infra) => new AadAuthTypeConnectionProperties()\n        {\n            Category = CognitiveServicesConnectionCategory.AzureBlob,\n            Target = storage.BlobEndpoint.AsProvisioningParameter(infra),\n            IsSharedToAll = true,\n            Metadata =\n            {\n                { \"ApiType\", \"Azure\" },\n                { \"ResourceId\", storage.Id.AsProvisioningParameter(infra) }\n            }\n        });\n    }\n\n    /// <summary>\n    /// Adds an Azure Storage account to a project as a connection.\n    /// </summary>\n    [AspireExport(\"addStorageConnection\")]","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Foundry/Project/ConnectionBuilderExtensions.cs#L119-L155","documentation":"Foundry project connections require a real Azure Storage account endpoint. AddConnection for Storage throws this InvalidOperationException when the supplied AzureStorageResource is running as the local emulator (Azurite), since Foundry cannot access it.","triggerScenarios":"Calling foundryProject.AddConnection(storage) where the AzureStorageResource builder had RunAsEmulator() applied (storage.IsEmulator() returns true).","commonSituations":"Local dev setups using Azurite while also registering a Foundry blob connection; templates that default resources to emulator mode for fast startup.","solutions":["Remove RunAsEmulator() from the Storage resource so a real account is provisioned.","Conditionally add the connection only when the storage resource is not emulated.","Declare a separate real Storage resource dedicated to the Foundry connection."],"exampleFix":"// before\nvar storage = builder.AddAzureStorage(\"storage\").RunAsEmulator();\nproject.AddConnection(storage); // throws\n\n// after\nvar storage = builder.AddAzureStorage(\"storage\");\nproject.AddConnection(storage);","handlingStrategy":"validation","validationCode":"if (!storage.IsEmulator())\n    project.AddConnection(storage);","typeGuard":null,"tryCatchPattern":"try { project.AddConnection(storage); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"emulator Storage\")) { /* skip or provision real Storage */ }","preventionTips":["Check storage.IsEmulator() before adding Foundry connections.","Avoid RunAsEmulator on resources that must serve as Foundry connection targets.","Split local-dev and deploy app models or condition resource emulation by execution context."],"tags":["azure-ai-foundry","azure-storage","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"}