microsoft/aspire · critical · InvalidOperationException

A MilvusClient could not be configured. Ensure valid…

Error message

A MilvusClient could not be configured. Ensure valid connection information was provided in 'ConnectionStrings:{connectionName}' or either {nameof(settings.Endpoint)} and {nameof(settings.Key)} must both be provided in the '{DefaultConfigSectionName}' or '{DefaultConfigSectionName}:{connectionName}' configuration sections.

What it means

MilvusClient creation requires an endpoint and an API key (or a connection string that supplies both). If, after config binding, either settings.Endpoint or settings.Key is null, the singleton factory throws because MilvusClient cannot be constructed. Both must be present together in the config sections or combined in the connection string.

Solutions

  1. Provide the full connection string in 'ConnectionStrings:{connectionName}' (endpoint and key combined).
  2. Or set both Endpoint and Key in the 'Aspire:Milvus:Client' or 'Aspire:Milvus:Client:{connectionName}' section — both keys are required together.
  3. Add WithReference(milvus) in the AppHost so the connection string is injected.
  4. Check for typos in the connection name and section keys.

Example fix

// before (appsettings.json)
{ "Aspire": { "Milvus": { "Client": { "Endpoint": "http://localhost:19530" } } } }
// after
{ "Aspire": { "Milvus": { "Client": { "Endpoint": "http://localhost:19530", "Key": "root:Milvus" } } } }
Defensive patterns

Strategy: validation

Validate before calling

// before resolving the Milvus client
var cs = builder.Configuration.GetConnectionString(connectionName);
var section = builder.Configuration.GetSection("Aspire:Milvus:Client");
if (string.IsNullOrEmpty(cs) && (section["Endpoint"] is null || section["Key"] is null))
{
    throw new InvalidOperationException($"Milvus endpoint and key must both be provided for '{connectionName}'.");
}

Type guard

bool HasMilvusInfo(string? cs, string? endpoint, string? key) => !string.IsNullOrEmpty(cs) || (endpoint is not null && key is not null);

Try / catch

try { var client = sp.GetRequiredService<MilvusClient>(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("A MilvusClient could not be configured")) { logger.LogCritical(ex, "Milvus connection info incomplete for {ConnectionName}", connectionName); throw; }

Prevention

When it happens

Trigger: Resolving a client registered with AddMilvusClient/AddKeyedMilvusClient when ConnectionStrings:{connectionName} is absent and 'Aspire:Milvus:Client' (or the per-connection-name section) does not contain both Endpoint and Key.

Common situations: Milvus container not referenced in the AppHost so no connection string is emitted; only the endpoint configured but the auth key forgotten (or vice versa); using username/password-style Milvus auth that doesn't map to the Key field; environment-specific appsettings dropping the section.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


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

Appendix: source

Thrown at src/Components/Aspire.Milvus.Client/AspireMilvusExtensions.cs:108

            builder.TryAddHealthCheck(new HealthCheckRegistration(
                serviceKey is null ? "Milvus" : $"Milvus_{connectionName}",
                sp => new MilvusHealthCheck(serviceKey is null
                    ? sp.GetRequiredService<MilvusClient>()
                    : sp.GetRequiredKeyedService<MilvusClient>(serviceKey)),
                failureStatus: default,
                tags: default,
                timeout: default));
        }

        MilvusClient ConfigureMilvus(IServiceProvider serviceProvider)
        {
            if (settings.Endpoint is not null && settings.Key is not null)
            {
                return new MilvusClient(settings.Endpoint, apiKey: settings.Key, database: settings.Database, loggerFactory: serviceProvider.GetRequiredService<ILoggerFactory>());
            }
            else
            {
                throw new InvalidOperationException(
                        $"A MilvusClient could not be configured. Ensure valid connection information was provided in 'ConnectionStrings:{connectionName}' or either " +
                        $"{nameof(settings.Endpoint)} and {nameof(settings.Key)} must both be provided " +
                        $"in the '{DefaultConfigSectionName}' or '{DefaultConfigSectionName}:{connectionName}' configuration sections.");
            }
        }
    }
}

View on GitHub (pinned to 25830f84bd)