{"record":{"id":"4139620f436ceb1f","repo":"microsoft/aspire","slug":"unable-to-resolve-the-durable-task-scheduler-connection","errorCode":null,"errorMessage":"Unable to resolve the Durable Task Scheduler connection string. Configure the scheduler using RunAsEmulator() or RunAsExisting(connectionString) before accessing ConnectionStringExpression.","messagePattern":"Unable to resolve the Durable Task Scheduler connection string\\. Configure the scheduler using RunAsEmulator\\(\\) or RunAsExisting\\(connectionString\\) before accessing ConnectionStringExpression\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Functions/DurableTask/DurableTaskSchedulerResource.cs","lineNumber":49,"sourceCode":"    {\n        if (IsEmulator)\n        {\n            var grpcEndpoint = new EndpointReference(this, \"grpc\");\n\n            return ReferenceExpression.Create($\"Endpoint={grpcEndpoint.Property(EndpointProperty.Scheme)}://{grpcEndpoint.Property(EndpointProperty.Host)}:{grpcEndpoint.Property(EndpointProperty.Port)};Authentication=None\");\n        }\n\n        if (this.TryGetLastAnnotation<DurableTaskSchedulerConnectionStringAnnotation>(out var connectionStringAnnotation))\n        {\n            return connectionStringAnnotation.ConnectionString switch\n            {\n                ParameterResource parameterResource => ReferenceExpression.Create($\"{parameterResource}\"),\n                string value => ReferenceExpression.Create($\"{value}\"),\n                _ => throw new InvalidOperationException($\"Unexpected connection string type: {connectionStringAnnotation.ConnectionString.GetType().Name}\"),\n            };\n        }\n\n        throw new InvalidOperationException($\"Unable to resolve the Durable Task Scheduler connection string. Configure the scheduler using {nameof(DurableTaskResourceExtensions.RunAsEmulator)}() or {nameof(DurableTaskResourceExtensions.RunAsExisting)}(connectionString) before accessing {nameof(ConnectionStringExpression)}.\");\n    }\n\n    private ReferenceExpression CreateDashboardEndpoint()\n    {\n        if (IsEmulator)\n        {\n            var dashboardEndpoint = new EndpointReference(this, \"dashboard\");\n\n            return ReferenceExpression.Create($\"{dashboardEndpoint.Property(EndpointProperty.Url)}\");\n        }\n\n        throw new InvalidOperationException(\"Dashboard endpoint is only available when running as an emulator.\");\n    }\n}\n","sourceCodeStart":31,"sourceCodeEnd":64,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Functions/DurableTask/DurableTaskSchedulerResource.cs#L31-L64","documentation":"When no DurableTaskSchedulerConnectionStringAnnotation exists at all, CreateConnectionString throws this InvalidOperationException explaining that the scheduler must first be configured with RunAsEmulator() or RunAsExisting(connectionString) before its ConnectionStringExpression can be read. It prevents dependent resources (e.g., task hubs, Functions apps) from resolving an undefined connection string.","triggerScenarios":"Accessing schedulerResource.ConnectionStringExpression (or adding a consuming resource that reads it) without ever calling RunAsEmulator() or RunAsExisting() on the scheduler builder.","commonSituations":"Defining a Durable Task scheduler but forgetting run-mode configuration; wiring a Functions app to the scheduler in publish-only scenarios without RunAsExisting; ordering issues where the connection is read before configuration.","solutions":["Call .RunAsEmulator() (local development) or .RunAsExisting(connectionStringOrParameter) on the DurableTaskSchedulerResource builder before referencing its connection string.","Ensure dependent resources are added after the scheduler is configured in run mode.","For deploy-only scenarios, provide the connection string via RunAsExisting with a parameter so it exists in the model."],"exampleFix":"// before\nvar scheduler = builder.AddDurableTaskScheduler(\"scheduler\");\nvar functions = builder.AddAzureFunctionsProject<Projects.FuncApp>(\"funcapp\")\n    .WithReference(scheduler); // no connection configured\n\n// after\nvar scheduler = builder.AddDurableTaskScheduler(\"scheduler\")\n    .RunAsExisting(builder.AddParameter(\"scheduler-conn\"));\nvar functions = builder.AddAzureFunctionsProject<Projects.FuncApp>(\"funcapp\")\n    .WithReference(scheduler);","handlingStrategy":"validation","validationCode":"bool configured = schedulerResource.Annotations.OfType<DurableTaskSchedulerConnectionStringAnnotation>().Any();\nif (!configured) throw new InvalidOperationException(\"Call RunAsEmulator() or RunAsExisting(...) before reading the scheduler connection string.\");","typeGuard":"static bool IsSchedulerConfigured(DurableTaskSchedulerResource r) => r.Annotations.OfType<DurableTaskSchedulerConnectionStringAnnotation>().Any();","tryCatchPattern":"try { var expr = scheduler.ConnectionStringExpression; } catch (InvalidOperationException ex) when (ex.Message.Contains(\"RunAsEmulator\")) { /* configure run mode, then retry */ }","preventionTips":["Always call RunAsEmulator or RunAsExisting before consuming the scheduler.","Configure the scheduler before adding dependent resources.","In publish scenarios supply a parameter-backed connection string via RunAsExisting."],"tags":["aspire","durable-task","connection-string","missing-configuration"],"backgroundTag":"missing-required-config","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"}