microsoft/aspire · error · InvalidOperationException

Resource ' ' not found.

Error message

Resource '{resourceName}' not found.

What it means

DcpExecutor.StopResourceAsync (and related reference lookup) resolves an Aspire model resource by name among resources that have a corresponding DCP resource which is not a Service. If no model resource with that name is found, it throws. It means the requested resource name does not exist in the running application model or is excluded from the DCP mapping.

Solutions

  1. Confirm the exact resource name with builder.Resources keys or the dashboard resource list before calling stop/start APIs.
  2. Check that the resource still exists after renames — update tooling/scripts that reference the old name.
  3. If targeting a service dependency, use the owning project/container resource name instead of the Service name.
  4. Add a guard that enumerates available resource references and fails fast with a helpful message.

Example fix

// before
await executor.StopResourceAsync("api", ct);
// after
var reference = executor.GetResourceReferences().FirstOrDefault(r =>
    string.Equals(r.DcpResourceName, "api", StringComparison.OrdinalIgnoreCase));
if (reference is null)
{
    throw new InvalidOperationException($"Resource 'api' is not part of this app. Available: {string.Join(", ", names)}");
}
await executor.StopResourceAsync(reference, ct);
Defensive patterns

Strategy: validation

Validate before calling

var exists = executor.GetResourceReferences()
    .Any(r => string.Equals(r.DcpResourceName, name, StringComparison.OrdinalIgnoreCase));
if (!exists) throw new InvalidOperationException($"Unknown resource '{name}'");

Type guard

static IResourceReference? FindByName(IEnumerable<IResourceReference> refs, string name) =>
    refs.FirstOrDefault(r => string.Equals(r.DcpResourceName, name, StringComparison.OrdinalIgnoreCase));

Try / catch

try { var r = ResolveReference(name); }
catch (InvalidOperationException ex) when (ex.Message == $"Resource '{name}' not found.")
{
    // surface available names to the caller
}

Prevention

When it happens

Trigger: Calling StopResourceAsync/GetResourceReference with a resourceName that does not match any IResource in the application model, or a name whose DCP resource is a Service (Services are filtered out), using case-different names (comparison is case-insensitive by ResourceName comparer but spelling must match).

Common situations: Dashboard or custom tooling issuing stop commands with stale/renamed resource names after code changes; passing a DCP service name instead of the Aspire resource name; typos in resource names from external automation scripts.

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/a04013408c3d4623. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting/Dcp/DcpExecutor.cs:1175

        var copy = JsonSerializer.Deserialize<T>(current)!;
        change(copy);

        var changed = JsonSerializer.SerializeToNode(copy);

        var jsonPatch = JsonPatch.Create(current, changed);
        return new V1Patch(jsonPatch, V1Patch.PatchType.JsonPatch);
    }

    public IResourceReference GetResource(string resourceName)
    {
        var matchingResource = _appResources.Get()
            .Where(r => r.DcpResource is not Service)
            .Where(r => string.Equals(r.DcpResource.Metadata.Name, resourceName, StringComparisons.ResourceName))
            .OfType<IResourceReference>().FirstOrDefault();
        if (matchingResource is null)
        {
            throw new InvalidOperationException($"Resource '{resourceName}' not found.");
        }

        return matchingResource;
    }

    public async Task StopResourceAsync(IResourceReference resourceReference, CancellationToken cancellationToken)
    {
        _logger.LogDebug("Stopping resource '{ResourceName}'...", resourceReference.DcpResourceName);
        var appResource = (IAppResource)resourceReference;
        bool stopped = false;

        using var activity = ProfilingTelemetry.StartResourceStop(_configuration, resourceReference.ModelResource, appResource.DcpResourceKind, appResource.DcpResourceName);
        try
        {
            // No concurrent start/stop operations on the same resource. Must wait for initialization to complete.
            await appResource.Initialized.WaitAsync(cancellationToken).ConfigureAwait(false);
            using var _ = await ConcurrencyUtils.AcquireAllAsync([appResource.SerializedOpSemaphore], cancellationToken).ConfigureAwait(false);

View on GitHub (pinned to 25830f84bd)