{"record":{"id":"7245f4b648f4d656","repo":"microsoft/aspire","slug":"the-connection-string-of-mongodb-replica-set-member-member","errorCode":null,"errorMessage":"The connection string of MongoDB replica set member '{member.Name}' could not be resolved.","messagePattern":"The connection string of MongoDB replica set member '(.+?)' could not be resolved\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.MongoDB/ReplicaSet/MongoDBReplicaSetBuilderExtensions.cs","lineNumber":158,"sourceCode":"                        .ConfigureAwait(false);\n\n                    await evt.Notifications.PublishUpdateAsync(resource, s => s with\n                    {\n                        State = KnownResourceStates.Starting,\n                    }).ConfigureAwait(false);\n\n                    if (membersList.Find(m => !m.TlsEnabled) is { } memberWithoutTls)\n                    {\n                        // NOTE: TLS is not optional for a replica set here: the `horizons` mechanism used below to advertise\n                        // host-reachable addresses to outside clients keys off the SNI of the incoming connection, which\n                        // only exists on TLS connections.\n                        throw new DistributedApplicationException($\"MongoDB replica set member '{memberWithoutTls.Name}' does not have TLS enabled, which is required for members of a replica set. Ensure an HTTPS/TLS certificate is available for the member, for example by trusting the ASP.NET Core developer certificate.\");\n                    }\n\n                    var memberConnections = await Task.WhenAll(membersList.Select(async member => new MemberConnection(\n                        member,\n                        await member.ConnectionStringExpression.GetValueAsync(ct).ConfigureAwait(false)\n                            ?? throw new DistributedApplicationException($\"The connection string of MongoDB replica set member '{member.Name}' could not be resolved.\")\n                    ))).ConfigureAwait(false);\n                    var initialPrimary = memberConnections[0];\n\n                    var memberHosts = await Task.WhenAll(membersList.Select(async m => new MemberHosts(\n                        // NOTE: `Internal` represents the host and port that should be accessible from within the MongoDB server's container.\n                        // NOTE: We know that the `TargetPort` always has a value (of 27017).\n                        Internal: $\"{m.Name}:{m.PrimaryEndpoint.TargetPort!.Value}\",\n                        // NOTE: `External` represents the host and port that would actually be advertised to outside clients, and should as such be accessible from outside the MongoDB server's container.\n                        External: await m.PrimaryEndpoint\n                            .Property(EndpointProperty.HostAndPort)\n                            .GetValueAsync(ct)\n                            .ConfigureAwait(false) ?? throw new DistributedApplicationException($\"The endpoint of MongoDB replica set member '{m.Name}' could not be resolved.\")\n                    ))).ConfigureAwait(false);\n\n                    var configured = false;\n                    var lastConfigurationError = null as MongoCommandException;\n                    for (var retries = 0; retries < MaxRetriesAttempt; retries++)\n                    {","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.MongoDB/ReplicaSet/MongoDBReplicaSetBuilderExtensions.cs#L140-L176","documentation":"During replica set initialization, the library resolves each member's ConnectionStringExpression to connect and configure the set. If GetValueAsync returns null for a member, it throws DistributedApplicationException stating the member's connection string could not be resolved.","triggerScenarios":"A MongoDB replica set member's connection string expression yields null at configuration time - usually because the member resource has no connection string generation (missing reference parameters, missing endpoint, or resource misconfiguration).","commonSituations":"Using a custom/derived MongoDB resource without a ConnectionStringExpression; dependency injection of reference parameters that aren't resolved; a member container that failed to start so its endpoint never materialized.","solutions":["Verify each member is a standard MongoDBServerResource created via AddMongoDB so it has a connection string expression","Ensure any reference parameters backing the connection string are provided (via --parameter or user secrets)","Check the member container actually starts (dashboard logs) - endpoint/connection string resolution depends on it","If using custom resources, override/implement ConnectionStringExpression to always return a usable value"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"var cs = await member.ConnectionStringExpression.GetValueAsync(ct);\nif (cs is null) throw new InvalidOperationException($\"Member {member.Name} has no connection string\");","typeGuard":null,"tryCatchPattern":"try { /* start app host */ }\ncatch (DistributedApplicationException ex) when (ex.Message.Contains(\"could not be resolved\")) { /* inspect member resource config/logs */ }","preventionTips":["Use standard AddMongoDB resources as members so connection strings always resolve","Provide required parameters via user secrets or CLI before launch","Confirm member containers start before replica set initialization"],"tags":["mongodb","replica-set","connection-string","resource-resolution"],"backgroundTag":"empty-result-set","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"}