{"record":{"id":"5114252911c1b058","repo":"microsoft/aspire","slug":"connectionstringavailableevent-was-published-for-the-511425","errorCode":null,"errorMessage":"ConnectionStringAvailableEvent was published for the '{rabbitMq.Name}' resource but the connection string was null.","messagePattern":"ConnectionStringAvailableEvent was published for the '(.+?)' resource but the connection string was null\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.RabbitMQ/RabbitMQBuilderExtensions.cs","lineNumber":53,"sourceCode":"        int? port = null)\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n        ArgumentException.ThrowIfNullOrEmpty(name);\n\n        // don't use special characters in the password, since it goes into a URI\n        var passwordParameter = password?.Resource ?? ParameterResourceBuilderExtensions.CreateDefaultPasswordParameter(builder, $\"{name}-password\", special: false);\n\n        var rabbitMq = new RabbitMQServerResource(name, userName?.Resource, passwordParameter);\n\n        string? connectionString = null;\n\n        builder.Eventing.Subscribe<ConnectionStringAvailableEvent>(rabbitMq, async (@event, ct) =>\n        {\n            connectionString = await rabbitMq.ConnectionStringExpression.GetValueAsync(ct).ConfigureAwait(false);\n\n            if (connectionString == null)\n            {\n                throw new DistributedApplicationException($\"ConnectionStringAvailableEvent was published for the '{rabbitMq.Name}' resource but the connection string was null.\");\n            }\n        });\n\n        var healthCheckKey = $\"{name}_check\";\n        // cache the connection so it is reused on subsequent calls to the health check\n        IConnection? connection = null;\n        builder.Services.AddHealthChecks().AddRabbitMQ(async (sp) =>\n        {\n            // NOTE: Ensure that execution of this setup callback is deferred until after\n            //       the container is built & started.\n            return connection ??= await CreateConnection(connectionString!).ConfigureAwait(false);\n\n            static Task<IConnection> CreateConnection(string connectionString)\n            {\n                var factory = new ConnectionFactory\n                {\n                    Uri = new Uri(connectionString)\n                };","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.RabbitMQ/RabbitMQBuilderExtensions.cs#L35-L71","documentation":"AddRabbitMQ subscribes to ConnectionStringAvailableEvent and resolves the resource's connection string. If the event fires but the resolved value is null — an internal consistency violation — it throws DistributedApplicationException naming the resource. This indicates the resource published a connection-string-available signal without actually having a connection string.","triggerScenarios":"The RabbitMQ resource's ConnectionStringExpression evaluates to null when ConnectionStringAvailableEvent is published during app startup.","commonSituations":"A custom RabbitMQ resource subclass overriding connection string logic incorrectly; connection string callbacks returning null; resource model mutations (bait-and-switch) breaking the expression binding.","solutions":["Ensure the RabbitMQ resource's connection string callback/expression always returns a non-null value.","If using a custom resource, verify it derives connection string from the host/port endpoints correctly.","Check for code that clears or replaces the resource's connection string configuration.","Update to the latest Aspire.Hosting.RabbitMQ package in case of a fixed model bug."],"exampleFix":"// before\nvar rabbitmq = builder.AddRabbitMQ(\"rabbitmq\").PublishAsConnectionString();\n\n// after\nvar rabbitmq = builder.AddRabbitMQ(\"rabbitmq\"); // let the default connection string expression resolve host/port","handlingStrategy":"try-catch","validationCode":"// Before subscribing/wiring, confirm the expression resolves\nvar value = await rabbitMq.ConnectionStringExpression.GetValueAsync(ct);\nif (value is null) { /* fix resource configuration */ }","typeGuard":null,"tryCatchPattern":"try\n{\n    await app.StartAsync();\n}\ncatch (DistributedApplicationException ex) when (ex.Message.Contains(\"ConnectionStringAvailableEvent\"))\n{\n    logger.LogError(ex, \"RabbitMQ connection string was null at startup; check resource configuration.\");\n    throw;\n}","preventionTips":["Do not override the RabbitMQ resource's connection string with custom logic returning null.","Keep default AddRabbitMQ wiring unless you fully replicate endpoint-derived connection strings.","Test AppHost startup locally before CI/deploy."],"tags":["rabbitmq","connection-string","eventing","aspire-hosting"],"backgroundTag":"internal-invariant-violation","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"}