microsoft/aspire · error · InvalidOperationException
Cannot create a Microsoft Foundry project connection to an…
Error message
Cannot create a Microsoft Foundry project connection to an emulator Storage account.
What it means
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.
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.
Example fix
// before
var storage = builder.AddAzureStorage("storage").RunAsEmulator();
project.AddConnection(storage); // throws
// after
var storage = builder.AddAzureStorage("storage");
project.AddConnection(storage); Defensive patterns
Strategy: validation
Validate before calling
if (!storage.IsEmulator())
project.AddConnection(storage); Try / catch
try { project.AddConnection(storage); } catch (InvalidOperationException ex) when (ex.Message.Contains("emulator Storage")) { /* skip or provision real Storage */ } Prevention
- 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.
When it happens
Trigger: Calling foundryProject.AddConnection(storage) where the AzureStorageResource builder had RunAsEmulator() applied (storage.IsEmulator() returns true).
Common situations: Local dev setups using Azurite while also registering a Foundry blob connection; templates that default resources to emulator mode for fast startup.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Cannot create a Microsoft Foundry project connection to an…
- Cannot create a Microsoft Foundry project connection to an…
- Cannot create a Microsoft Foundry project connection to an…
- BlobServiceClient is not initialized.
- Emulator currently does not support data lake.
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/bfaf485121bbc6f6.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Foundry/Project/ConnectionBuilderExtensions.cs:137
IResourceBuilder<AzureCosmosDBResource> db)
{
return builder.AddConnection(db.Resource);
}
/// <summary>
/// Adds an Azure Storage account to a project as a connection.
/// </summary>
/// <returns></returns>
[AspireExportIgnore(Reason = "Raw AzureStorageResource parameters are not ATS-compatible. Use the resource-builder overload instead.")]
public static IResourceBuilder<AzureCognitiveServicesProjectConnectionResource> AddConnection(
this IResourceBuilder<AzureCognitiveServicesProjectResource> builder,
AzureStorageResource storage)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(storage);
if (storage.IsEmulator())
{
throw new InvalidOperationException("Cannot create a Microsoft Foundry project connection to an emulator Storage account.");
}
return builder.AddConnection($"connection-{Guid.NewGuid():N}", (infra) => new AadAuthTypeConnectionProperties()
{
Category = CognitiveServicesConnectionCategory.AzureBlob,
Target = storage.BlobEndpoint.AsProvisioningParameter(infra),
IsSharedToAll = true,
Metadata =
{
{ "ApiType", "Azure" },
{ "ResourceId", storage.Id.AsProvisioningParameter(infra) }
}
});
}
/// <summary>
/// Adds an Azure Storage account to a project as a connection.
/// </summary>
[AspireExport("addStorageConnection")]View on GitHub (pinned to 25830f84bd)