{"record":{"id":"7e9e3d34c31a06e8","repo":"microsoft/aspire","slug":"the-azure-storage-resource-is-not-running-in-the-local","errorCode":null,"errorMessage":"The Azure Storage resource is not running in the local emulator.","messagePattern":"The Azure Storage resource is not running in the local emulator\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Storage/AzureStorageResource.cs","lineNumber":133,"sourceCode":"        : ReferenceExpression.Create($\"{QueueEndpoint}\");\n\n    /// <summary>\n    /// Gets the connection URI expression for the table storage service.\n    /// </summary>\n    /// <remarks>\n    /// Format: <c>https://{host}:{port}</c> for emulator or <c>{tableEndpoint}</c> for Azure.\n    /// </remarks>\n    public ReferenceExpression TableUriExpression => IsEmulator\n        ? ReferenceExpression.Create($\"{EmulatorTableEndpoint.Property(EndpointProperty.Url)}\")\n        : ReferenceExpression.Create($\"{TableEndpoint}\");\n\n    /// <summary>\n    /// Gets the connection string for the Azure Storage emulator.\n    /// </summary>\n    /// <returns>The connection string for the Azure Storage emulator.</returns>\n    internal ReferenceExpression GetEmulatorConnectionString() => IsEmulator\n       ? AzureStorageEmulatorConnectionString.Create(blobEndpoint: EmulatorBlobEndpoint, queueEndpoint: EmulatorQueueEndpoint, tableEndpoint: EmulatorTableEndpoint)\n       : throw new InvalidOperationException(\"The Azure Storage resource is not running in the local emulator.\");\n\n    internal ReferenceExpression GetTableConnectionString() => IsEmulator\n        ? AzureStorageEmulatorConnectionString.Create(tableEndpoint: EmulatorTableEndpoint)\n        : ReferenceExpression.Create($\"{TableEndpoint}\");\n\n    internal ReferenceExpression GetQueueConnectionString() => IsEmulator\n        ? AzureStorageEmulatorConnectionString.Create(queueEndpoint: EmulatorQueueEndpoint)\n        : ReferenceExpression.Create($\"{QueueEndpoint}\");\n\n    internal ReferenceExpression GetBlobConnectionString() => IsEmulator\n        ? AzureStorageEmulatorConnectionString.Create(blobEndpoint: EmulatorBlobEndpoint)\n        : ReferenceExpression.Create($\"{BlobEndpoint}\");\n\n    internal ReferenceExpression GetDataLakeConnectionString() => IsEmulator\n        ? throw new InvalidOperationException(\"Emulator currently does not support data lake.\")\n        : ReferenceExpression.Create($\"{DataLakeEndpoint}\");\n\n    void IResourceWithAzureFunctionsConfig.ApplyAzureFunctionsConfiguration(IDictionary<string, object> target, string connectionName)","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Storage/AzureStorageResource.cs#L115-L151","documentation":"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.","triggerScenarios":"Invoking GetEmulatorConnectionString() (internal; reachable via connectionString resolution paths) on an AzureStorageResource that was created without RunAsEmulator(), so IsEmulator is false.","commonSituations":"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.","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"],"exampleFix":"// before\nvar cs = storageResource.GetEmulatorConnectionString(); // may throw\n// after\nvar cs = storageResource.IsEmulator\n    ? storageResource.GetEmulatorConnectionString()\n    : storageResource.BlobUriExpression;","handlingStrategy":"validation","validationCode":"if (!storageResource.IsEmulator)\n    throw new InvalidOperationException(\"GetEmulatorConnectionString is only valid for emulator-configured storage resources.\");","typeGuard":"static bool IsEmulatorStorage(AzureStorageResource r) => r.IsEmulator;","tryCatchPattern":"try { cs = resource.GetEmulatorConnectionString(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"not running in the local emulator\")) { cs = resource.BlobUriExpression; }","preventionTips":["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"],"tags":["azure-storage","emulator","connection-string","invalid-state"],"backgroundTag":"invalid-state-transition","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}