microsoft/aspire · error · InvalidOperationException
The Azure Storage resource is not running in the local…
Error message
The Azure Storage resource is not running in the local emulator.
What it means
GetEmulatorConnectionString builds the well-known Azurite connection string from the emulator endpoints, and is only valid when IsEmulator is true. Calling it on a storage resource configured for real Azure throws this InvalidOperationException because there are no emulator endpoints to compose.
Solutions
- Only call GetEmulatorConnectionString when resource.IsEmulator is true
- For real Azure resources use GetTableConnectionString/GetQueueConnectionString or the resource's endpoint expressions
- Apply RunAsEmulator() to the storage resource if emulator behavior is what you intend
Example fix
// before
var cs = storageResource.GetEmulatorConnectionString(); // may throw
// after
var cs = storageResource.IsEmulator
? storageResource.GetEmulatorConnectionString()
: storageResource.BlobUriExpression; Defensive patterns
Strategy: validation
Validate before calling
if (!storageResource.IsEmulator)
throw new InvalidOperationException("GetEmulatorConnectionString is only valid for emulator-configured storage resources."); Type guard
static bool IsEmulatorStorage(AzureStorageResource r) => r.IsEmulator;
Try / catch
try { cs = resource.GetEmulatorConnectionString(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("not running in the local emulator")) { cs = resource.BlobUriExpression; } Prevention
- Check IsEmulator before calling emulator-only members
- Use the endpoint/connection expressions that handle both emulator and real Azure modes
- Apply RunAsEmulator() when emulator behavior is intended
When it happens
Trigger: Invoking GetEmulatorConnectionString() (internal; reachable via connectionString resolution paths) on an AzureStorageResource that was created without RunAsEmulator(), so IsEmulator is false.
Common situations: Internal/extension code that assumes the emulator path but runs against a cloud-configured resource; custom code mimicking the emulator wiring on a production-configured resource; tests switching resource modes.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- BlobServiceClient is not initialized.
- Cannot create a Microsoft Foundry project connection to an…
- Connection string is not initialized.
- ConnectionStringAvailableEvent was published for the
- Could not find a with name .
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/7e9e3d34c31a06e8.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.Storage/AzureStorageResource.cs:133
: ReferenceExpression.Create($"{QueueEndpoint}");
/// <summary>
/// Gets the connection URI expression for the table storage service.
/// </summary>
/// <remarks>
/// Format: <c>https://{host}:{port}</c> for emulator or <c>{tableEndpoint}</c> for Azure.
/// </remarks>
public ReferenceExpression TableUriExpression => IsEmulator
? ReferenceExpression.Create($"{EmulatorTableEndpoint.Property(EndpointProperty.Url)}")
: ReferenceExpression.Create($"{TableEndpoint}");
/// <summary>
/// Gets the connection string for the Azure Storage emulator.
/// </summary>
/// <returns>The connection string for the Azure Storage emulator.</returns>
internal ReferenceExpression GetEmulatorConnectionString() => IsEmulator
? AzureStorageEmulatorConnectionString.Create(blobEndpoint: EmulatorBlobEndpoint, queueEndpoint: EmulatorQueueEndpoint, tableEndpoint: EmulatorTableEndpoint)
: throw new InvalidOperationException("The Azure Storage resource is not running in the local emulator.");
internal ReferenceExpression GetTableConnectionString() => IsEmulator
? AzureStorageEmulatorConnectionString.Create(tableEndpoint: EmulatorTableEndpoint)
: ReferenceExpression.Create($"{TableEndpoint}");
internal ReferenceExpression GetQueueConnectionString() => IsEmulator
? AzureStorageEmulatorConnectionString.Create(queueEndpoint: EmulatorQueueEndpoint)
: ReferenceExpression.Create($"{QueueEndpoint}");
internal ReferenceExpression GetBlobConnectionString() => IsEmulator
? AzureStorageEmulatorConnectionString.Create(blobEndpoint: EmulatorBlobEndpoint)
: ReferenceExpression.Create($"{BlobEndpoint}");
internal ReferenceExpression GetDataLakeConnectionString() => IsEmulator
? throw new InvalidOperationException("Emulator currently does not support data lake.")
: ReferenceExpression.Create($"{DataLakeEndpoint}");
void IResourceWithAzureFunctionsConfig.ApplyAzureFunctionsConfiguration(IDictionary<string, object> target, string connectionName)View on GitHub (pinned to 25830f84bd)