{"record":{"id":"a04013408c3d4623","repo":"microsoft/aspire","slug":"resource-resourcename-not-found-dcpexecutor","errorCode":null,"errorMessage":"Resource '{resourceName}' not found.","messagePattern":"Resource '(.+?)' not found\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/Dcp/DcpExecutor.cs","lineNumber":1175,"sourceCode":"\n        var copy = JsonSerializer.Deserialize<T>(current)!;\n        change(copy);\n\n        var changed = JsonSerializer.SerializeToNode(copy);\n\n        var jsonPatch = JsonPatch.Create(current, changed);\n        return new V1Patch(jsonPatch, V1Patch.PatchType.JsonPatch);\n    }\n\n    public IResourceReference GetResource(string resourceName)\n    {\n        var matchingResource = _appResources.Get()\n            .Where(r => r.DcpResource is not Service)\n            .Where(r => string.Equals(r.DcpResource.Metadata.Name, resourceName, StringComparisons.ResourceName))\n            .OfType<IResourceReference>().FirstOrDefault();\n        if (matchingResource is null)\n        {\n            throw new InvalidOperationException($\"Resource '{resourceName}' not found.\");\n        }\n\n        return matchingResource;\n    }\n\n    public async Task StopResourceAsync(IResourceReference resourceReference, CancellationToken cancellationToken)\n    {\n        _logger.LogDebug(\"Stopping resource '{ResourceName}'...\", resourceReference.DcpResourceName);\n        var appResource = (IAppResource)resourceReference;\n        bool stopped = false;\n\n        using var activity = ProfilingTelemetry.StartResourceStop(_configuration, resourceReference.ModelResource, appResource.DcpResourceKind, appResource.DcpResourceName);\n        try\n        {\n            // No concurrent start/stop operations on the same resource. Must wait for initialization to complete.\n            await appResource.Initialized.WaitAsync(cancellationToken).ConfigureAwait(false);\n            using var _ = await ConcurrencyUtils.AcquireAllAsync([appResource.SerializedOpSemaphore], cancellationToken).ConfigureAwait(false);\n","sourceCodeStart":1157,"sourceCodeEnd":1193,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/Dcp/DcpExecutor.cs#L1157-L1193","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Confirm the exact resource name with builder.Resources keys or the dashboard resource list before calling stop/start APIs.","Check that the resource still exists after renames — update tooling/scripts that reference the old name.","If targeting a service dependency, use the owning project/container resource name instead of the Service name.","Add a guard that enumerates available resource references and fails fast with a helpful message."],"exampleFix":"// before\nawait executor.StopResourceAsync(\"api\", ct);\n// after\nvar reference = executor.GetResourceReferences().FirstOrDefault(r =>\n    string.Equals(r.DcpResourceName, \"api\", StringComparison.OrdinalIgnoreCase));\nif (reference is null)\n{\n    throw new InvalidOperationException($\"Resource 'api' is not part of this app. Available: {string.Join(\", \", names)}\");\n}\nawait executor.StopResourceAsync(reference, ct);","handlingStrategy":"validation","validationCode":"var exists = executor.GetResourceReferences()\n    .Any(r => string.Equals(r.DcpResourceName, name, StringComparison.OrdinalIgnoreCase));\nif (!exists) throw new InvalidOperationException($\"Unknown resource '{name}'\");","typeGuard":"static IResourceReference? FindByName(IEnumerable<IResourceReference> refs, string name) =>\n    refs.FirstOrDefault(r => string.Equals(r.DcpResourceName, name, StringComparison.OrdinalIgnoreCase));","tryCatchPattern":"try { var r = ResolveReference(name); }\ncatch (InvalidOperationException ex) when (ex.Message == $\"Resource '{name}' not found.\")\n{\n    // surface available names to the caller\n}","preventionTips":["Source resource names from the model (builder.Resources) instead of hardcoded strings","Update external scripts after renaming resources","Never pass DCP Service names where Aspire resource names are expected"],"tags":["dcp","resource-not-found","naming"],"backgroundTag":"resource-not-found","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}