{"record":{"id":"3efcaffecefeede3","repo":"microsoft/aspire","slug":"resource-resource-name-cannot-produce-a","errorCode":null,"errorMessage":"Resource '{resource.Name}' cannot produce a \"{KnownLaunchConfigurationTypes.Project}\" launch configuration because it has no project metadata. The \"{KnownLaunchConfigurationTypes.Project}\" launch configuration type is reserved for .NET project resources; use a resource that carries IProjectMetadata or a different launch configuration type.","messagePattern":"Resource '(.+?)' cannot produce a \"(.+?)\" launch configuration because it has no project metadata\\. The \"(.+?)\" launch configuration type is reserved for \\.NET project resources; use a resource that carries IProjectMetadata or a different launch configuration type\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/ApplicationModel/ProjectLaunchConfigurationFactory.cs","lineNumber":18,"sourceCode":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n\n#pragma warning disable ASPIREEXTENSION001\n#pragma warning disable ASPIREPROJECTS001\n\nnamespace Aspire.Hosting.ApplicationModel;\n\n/// <summary>\n/// Builds the <see cref=\"ProjectLaunchConfiguration\"/> that Aspire hands to the IDE for a .NET resource.\n/// </summary>\ninternal static class ProjectLaunchConfigurationFactory\n{\n    public static ProjectLaunchConfiguration Create(IResource resource, string mode)\n    {\n        if (!resource.TryGetProjectMetadata(out var projectMetadata))\n        {\n            throw new InvalidOperationException(\n                $\"Resource '{resource.Name}' cannot produce a \\\"{KnownLaunchConfigurationTypes.Project}\\\" launch configuration because it has no project metadata. \" +\n                $\"The \\\"{KnownLaunchConfigurationTypes.Project}\\\" launch configuration type is reserved for .NET project resources; use a resource that carries {nameof(IProjectMetadata)} or a different launch configuration type.\");\n        }\n\n        return Create(resource, projectMetadata, mode);\n    }\n\n    public static ProjectLaunchConfiguration Create(IResource resource, IProjectMetadata projectMetadata, string mode)\n    {\n        resource.TryGetLastAnnotation<ProjectLaunchDefaultsAnnotation>(out var launchDefaults);\n        var projectLaunchConfiguration = new ProjectLaunchConfiguration\n        {\n            Type = GetLaunchConfigurationType(resource, projectMetadata),\n            ProjectPath = projectMetadata.ProjectPath,\n            Mode = mode,\n            BuildConfiguration = launchDefaults?.BuildConfiguration,\n            BuildEnvironment = projectMetadata.BuildEnvironment.Count == 0\n                ? null","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ApplicationModel/ProjectLaunchConfigurationFactory.cs#L1-L36","documentation":"ProjectLaunchConfigurationFactory.Create only produces a 'Project' launch configuration for resources that carry IProjectMetadata. Given any other resource type (container, executable, connection), it throws InvalidOperationException because the 'Project' configuration type is reserved for .NET project resources.","triggerScenarios":"Requesting launch configurations for a resource whose annotation list lacks IProjectMetadata, e.g. resolving launch configurations for a container resource or a plain custom resource.","commonSituations":"Enumerating launch configurations over all resources in the app model where non-project resources are included; a custom resource builder forgot to add project metadata; dashboard/IDE tooling asking for a project config for a container.","solutions":["Only request project launch configurations for resources where resource.TryGetProjectMetadata(out _) returns true","Use the launch configuration factory that matches the resource's actual kind (e.g. container/executable configuration types)","If the resource should be a project, add the project metadata annotation in the resource builder"],"exampleFix":"// before\nvar config = ProjectLaunchConfigurationFactory.Create(resource, mode);\n// after\nif (resource.TryGetProjectMetadata(out _))\n{\n    var config = ProjectLaunchConfigurationFactory.Create(resource, mode);\n}","handlingStrategy":"type-guard","validationCode":"if (!resource.TryGetProjectMetadata(out _))\n    throw new InvalidOperationException($\"'{resource.Name}' is not a project resource.\");","typeGuard":"bool IsProjectResource(IResource r) => r.TryGetProjectMetadata(out _);","tryCatchPattern":"try { var cfg = ProjectLaunchConfigurationFactory.Create(resource, mode); } catch (InvalidOperationException) { /* use the resource's actual launch config type */ }","preventionTips":["Filter resource collections with TryGetProjectMetadata before requesting project configs","Use the config type matching the resource kind"],"tags":["launch-configuration","project-metadata","aspire-hosting"],"backgroundTag":"missing-dependency","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"}