microsoft/aspire · error · DistributedApplicationException

ConnectionStringAvailableEvent was published for the

Error message

ConnectionStringAvailableEvent was published for the '{rabbitMq.Name}' resource but the connection string was null.

What it means

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.

Solutions

  1. Ensure the RabbitMQ resource's connection string callback/expression always returns a non-null value.
  2. If using a custom resource, verify it derives connection string from the host/port endpoints correctly.
  3. Check for code that clears or replaces the resource's connection string configuration.
  4. Update to the latest Aspire.Hosting.RabbitMQ package in case of a fixed model bug.

Example fix

// before
var rabbitmq = builder.AddRabbitMQ("rabbitmq").PublishAsConnectionString();

// after
var rabbitmq = builder.AddRabbitMQ("rabbitmq"); // let the default connection string expression resolve host/port
Defensive patterns

Strategy: try-catch

Validate before calling

// Before subscribing/wiring, confirm the expression resolves
var value = await rabbitMq.ConnectionStringExpression.GetValueAsync(ct);
if (value is null) { /* fix resource configuration */ }

Try / catch

try
{
    await app.StartAsync();
}
catch (DistributedApplicationException ex) when (ex.Message.Contains("ConnectionStringAvailableEvent"))
{
    logger.LogError(ex, "RabbitMQ connection string was null at startup; check resource configuration.");
    throw;
}

Prevention

When it happens

Trigger: The RabbitMQ resource's ConnectionStringExpression evaluates to null when ConnectionStringAvailableEvent is published during app startup.

Common situations: 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.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/5114252911c1b058. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.RabbitMQ/RabbitMQBuilderExtensions.cs:53

        int? port = null)
    {
        ArgumentNullException.ThrowIfNull(builder);
        ArgumentException.ThrowIfNullOrEmpty(name);

        // don't use special characters in the password, since it goes into a URI
        var passwordParameter = password?.Resource ?? ParameterResourceBuilderExtensions.CreateDefaultPasswordParameter(builder, $"{name}-password", special: false);

        var rabbitMq = new RabbitMQServerResource(name, userName?.Resource, passwordParameter);

        string? connectionString = null;

        builder.Eventing.Subscribe<ConnectionStringAvailableEvent>(rabbitMq, async (@event, ct) =>
        {
            connectionString = await rabbitMq.ConnectionStringExpression.GetValueAsync(ct).ConfigureAwait(false);

            if (connectionString == null)
            {
                throw new DistributedApplicationException($"ConnectionStringAvailableEvent was published for the '{rabbitMq.Name}' resource but the connection string was null.");
            }
        });

        var healthCheckKey = $"{name}_check";
        // cache the connection so it is reused on subsequent calls to the health check
        IConnection? connection = null;
        builder.Services.AddHealthChecks().AddRabbitMQ(async (sp) =>
        {
            // NOTE: Ensure that execution of this setup callback is deferred until after
            //       the container is built & started.
            return connection ??= await CreateConnection(connectionString!).ConfigureAwait(false);

            static Task<IConnection> CreateConnection(string connectionString)
            {
                var factory = new ConnectionFactory
                {
                    Uri = new Uri(connectionString)
                };

View on GitHub (pinned to 25830f84bd)