microsoft/aspire · error · ArgumentException

Resource ' ' not found.

Error message

Resource '{resourceName}' not found.

What it means

GetResource throws this ArgumentException when no resource with the given name exists in the DistributedApplicationModel. The lookup uses the model's name-based resource collection (TryGetByName) and fails fast when the name doesn't match any registered resource.

Solutions

  1. Verify the exact resource name as passed to AddXxx in the AppHost, including casing
  2. List app.Services.GetRequiredService<DistributedApplicationModel>().Resources to see valid names
  3. Ensure the resource isn't added conditionally for the test's execution context

Example fix

// before
var redis = app.GetResource("cache"); // actual name "redis"
// after
var redis = app.GetResource("redis");
Defensive patterns

Strategy: validation

Validate before calling

var model = app.Services.GetRequiredService<DistributedApplicationModel>();
bool exists = model.Resources.Any(r => string.Equals(r.Name, name, StringComparison.OrdinalIgnoreCase));

Try / catch

try { var resource = app.GetResource(name); }
catch (ArgumentException)
{
    // name doesn't match any model resource; list resources to debug
}

Prevention

When it happens

Trigger: Calling app.GetResource("name") (or GetConnectionStringAsync/GetEndpointAsync which call it) with a name that doesn't match any resource in the app model — wrong name, wrong casing, or resource added under a different name.

Common situations: Typo in resource name; renames of AddXxx calls not propagated to tests; adding resources conditionally (e.g. only in publish mode) so tests can't find them; case-sensitivity mismatches.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

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

    /// <param name="networkIdentifier">The optional network identifier string. If none is specified, the default network is used.</param>
    /// <param name="endpointName">The optional endpoint name. If none is specified, the "https" endpoint is preferred when available, falling back to "http".</param>
    /// <returns>A URI representation of the endpoint.</returns>
    /// <exception cref="ArgumentException">The resource was not found, no matching endpoint was found, or multiple endpoints were found.</exception>
    /// <exception cref="InvalidOperationException">The resource has no endpoints.</exception>
    [AspireExport]
    internal static Uri GetEndpointForNetworkExport(this DistributedApplication app, string resourceName, string? networkIdentifier = default, string? endpointName = default)
    {
        return app.GetEndpointForNetwork(resourceName, networkIdentifier is null ? null : new NetworkIdentifier(networkIdentifier), endpointName);
    }

    static IResource GetResource(DistributedApplication app, string resourceName)
    {
        ThrowIfNotStarted(app, Properties.Resources.ApplicationNotStartedExceptionMessage);
        var applicationModel = app.Services.GetRequiredService<DistributedApplicationModel>();

        if (!applicationModel.Resources.TryGetByName(resourceName, out var resource))
        {
            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.ResourceNotFoundExceptionMessage, resourceName), nameof(resourceName));
        }

        return resource;
    }

    static string GetEndpointUriStringCore(DistributedApplication app, string resourceName, string? endpointName = default, NetworkIdentifier? networkIdentifier = default)
    {
        var resource = GetResource(app, resourceName);
        if (resource is not IResourceWithEndpoints resourceWithEndpoints)
        {
            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.ResourceHasNoAllocatedEndpointsExceptionMessage, resourceName), nameof(resourceName));
        }

        EndpointReference? endpoint;
        if (!string.IsNullOrEmpty(endpointName))
        {
            endpoint = GetEndpointOrDefault(resourceWithEndpoints, endpointName, networkIdentifier);
        }

View on GitHub (pinned to 25830f84bd)