microsoft/aspire · error · ArgumentException

Resource ' ' does not expose a connection string.

Error message

Resource '{resourceName}' does not expose a connection string.

What it means

GetConnectionStringAsync throws this ArgumentException when the named resource exists in the application model but does not implement IResourceWithConnectionString, so it has no connection string to expose. The library only supports retrieving connection strings from resources that declare one.

Solutions

  1. Pass the name of the resource that actually owns the connection string (e.g. the postgres/sqlserver resource, not the consuming project)
  2. If it's a custom resource, implement IResourceWithConnectionString on it
  3. Use GetResource to inspect the resource type before calling GetConnectionStringAsync

Example fix

// before
var cs = await app.GetConnectionStringAsync("frontend"); // project resource
// after
var cs = await app.GetConnectionStringAsync("postgres"); // resource with connection string
Defensive patterns

Strategy: type-guard

Validate before calling

var resource = app.GetResource(name);
bool hasCs = resource is IResourceWithConnectionString;

Type guard

static bool ExposesConnectionString(DistributedApplication app, string name) =>
    app.GetResource(name) is IResourceWithConnectionString;

Try / catch

try { var cs = await app.GetConnectionStringAsync(name); }
catch (ArgumentException ex) when (ex.ParamName == "resourceName")
{
    // resource has no connection string; use GetEndpoint or a different resource
}

Prevention

When it happens

Trigger: Calling app.GetConnectionStringAsync(appName, "resourceName") for a resource type without a connection string — e.g. a project resource, executable, or a container without connection-string annotations.

Common situations: Passing a project/frontend resource name instead of the database resource; using a custom resource type that doesn't implement IResourceWithConnectionString; typos mapping to the wrong resource.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting.Testing/DistributedApplicationHostingTestingExtensions.cs:179

    /// <summary>
    /// Gets the connection string for the specified resource.
    /// </summary>
    /// <param name="app">The application.</param>
    /// <param name="resourceName">The resource name.</param>
    /// <param name="cancellationToken">A <see cref="CancellationToken"/>.</param>
    /// <remarks>This overload is not available in polyglot app hosts. Use the exported overload without a cancellation token instead.</remarks>
    /// <returns>The connection string for the specified resource.</returns>
    /// <exception cref="ArgumentException">The resource was not found or does not expose a connection string.</exception>
    [AspireExportIgnore(Reason = "Use the exported getConnectionString overload without a cancellation token.")]
    public static ValueTask<string?> GetConnectionStringAsync(this DistributedApplication app, string resourceName, CancellationToken cancellationToken = default)
    {
        ArgumentNullException.ThrowIfNull(app);
        ArgumentException.ThrowIfNullOrEmpty(resourceName);

        var resource = GetResource(app, resourceName);
        if (resource is not IResourceWithConnectionString resourceWithConnectionString)
        {
            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.ResourceDoesNotExposeConnectionStringExceptionMessage, resourceName), nameof(resourceName));
        }

        return resourceWithConnectionString.GetConnectionStringAsync(cancellationToken);
    }

    /// <summary>
    /// Gets the connection string for the specified resource.
    /// </summary>
    /// <param name="app">The application.</param>
    /// <param name="resourceName">The resource name.</param>
    /// <returns>The connection string for the specified resource.</returns>
    /// <exception cref="ArgumentException">The resource was not found or does not expose a connection string.</exception>
    [AspireExport("getConnectionString")]
    internal static Task<string?> GetConnectionStringAsyncExport(this DistributedApplication app, string resourceName)
    {
        return app.GetConnectionStringAsync(resourceName, default).AsTask();
    }

View on GitHub (pinned to 25830f84bd)