microsoft/aspire · error · InvalidOperationException

Connection string is unavailable

Error message

Connection string is unavailable

What it means

CreateQdrantClient builds a QdrantClient from the resource's connection string. When the connection string is null — meaning no connection information was ever associated with the Qdrant resource — it throws InvalidOperationException('Connection string is unavailable'). The library requires at least a connection string to derive an endpoint for the client.

Solutions

  1. Provide a connection string via AddQdrant's connectionString parameter or a callback that returns one.
  2. Set up the resource's connection string with WithReference/RunWithConnectionString so it resolves at runtime.
  3. Verify the resource name used in WithReference matches the Qdrant resource name.
  4. Inspect the resolved configuration (e.g. ConnectionStrings__qdrant) to confirm the value exists.

Example fix

// before
var qdrant = builder.AddQdrant("qdrant");

// after
var qdrant = builder.AddQdrant("qdrant", connectionString: builder.Configuration.GetConnectionString("qdrant"));
Defensive patterns

Strategy: validation

Validate before calling

var cs = builder.Configuration.GetConnectionString("qdrant");
if (string.IsNullOrEmpty(cs))
{
    throw new InvalidOperationException("Set ConnectionStrings:qdrant before starting the AppHost.");
}

Prevention

When it happens

Trigger: AddQdrant invoked without a client and the resolved connection string parameter is null, e.g. the resource has no ConnectionStringExpression value and no explicit connection string argument was supplied.

Common situations: Forgetting to call RunWithConnectionString or not setting a connection string on the Qdrant resource; referencing the resource by a mismatched name; creating the resource in publish-only scenarios where the runtime value is absent.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting.Qdrant/QdrantBuilderExtensions.cs:198

        {
            builder.WithEnvironment(context =>
            {
                // primary endpoint (gRPC)
                context.EnvironmentVariables[$"{connectionStringName}"] = qdrantResource.Resource.ConnectionStringExpression;

                // HTTP endpoint
                context.EnvironmentVariables[$"{connectionStringName}_{QdrantServerResource.HttpEndpointName}"] = qdrantResource.Resource.HttpConnectionStringExpression;
            });
        }

        return builder;
    }

    private static QdrantClient CreateQdrantClient(string? connectionString)
    {
        if (connectionString is null)
        {
            throw new InvalidOperationException("Connection string is unavailable");
        }

        Uri? endpoint = null;
        string? key = null;

        if (Uri.TryCreate(connectionString, UriKind.Absolute, out var uri))
        {
            endpoint = uri;
        }
        else
        {
            var connectionBuilder = new DbConnectionStringBuilder
            {
                ConnectionString = connectionString
            };

            if (connectionBuilder.TryGetValue("Endpoint", out var endpointValue) && Uri.TryCreate(endpointValue.ToString(), UriKind.Absolute, out var serviceUri))
            {

View on GitHub (pinned to 25830f84bd)