{"record":{"id":"5125b23d17103877","repo":"microsoft/aspire","slug":"unexpected-connection-string-type-connectionstringannotation","errorCode":null,"errorMessage":"Unexpected connection string type: {connectionStringAnnotation.ConnectionString.GetType().Name}","messagePattern":"Unexpected connection string type: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Functions/DurableTask/DurableTaskSchedulerResource.cs","lineNumber":45,"sourceCode":"    /// </summary>\n    public bool IsEmulator => this.IsContainer();\n\n    private ReferenceExpression CreateConnectionString()\n    {\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}","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Functions/DurableTask/DurableTaskSchedulerResource.cs#L27-L63","documentation":"DurableTaskSchedulerResource.CreateConnectionString resolves the connection string stored in DurableTaskSchedulerConnectionStringAnnotation. The stored value must be a string or ParameterResource; any other type indicates an internal misuse of the annotation, so an InvalidOperationException naming the type is thrown while building ConnectionStringExpression.","triggerScenarios":"Reading ConnectionStringExpression on a scheduler resource whose connection-string annotation was populated by custom/incorrect code with an unsupported type (e.g., a ReferenceExpression or IResourceBuilder).","commonSituations":"Custom Durable Task extension code storing an unvalidated object in the annotation; a version mismatch where an older integration stored a different representation.","solutions":["Configure the scheduler only through the supported APIs: RunAsEmulator() or RunAsExisting(string | IResourceBuilder<ParameterResource>).","Fix the code that constructs DurableTaskSchedulerConnectionStringAnnotation to store a string or ParameterResource.","Update integration packages so the annotation producer and consumer agree on the stored type."],"exampleFix":"// before\nannotation = new DurableTaskSchedulerConnectionStringAnnotation(expressionObject); // wrong type\n\n// after\nvar connParam = builder.AddParameter(\"scheduler-conn\");\nschedulerBuilder.RunAsExisting(connParam); // stores ParameterResource","handlingStrategy":"type-guard","validationCode":"if (value is not string and not ParameterResource) throw new InvalidOperationException(\"DurableTaskSchedulerConnectionStringAnnotation requires string or ParameterResource.\");","typeGuard":"static bool IsValidConnectionStringAnnotation(object? v) => v is string or ParameterResource;","tryCatchPattern":"try { var expr = scheduler.ConnectionStringExpression; } catch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Unexpected connection string type\")) { /* fix the code storing the annotation */ }","preventionTips":["Configure schedulers only via RunAsEmulator/RunAsExisting.","Store only string or ParameterResource in the connection-string annotation.","Keep integration packages version-aligned."],"tags":["aspire","durable-task","connection-string","type-mismatch"],"backgroundTag":"type-mismatch","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"}