{"record":{"id":"bacec90a49694a01","repo":"microsoft/aspire","slug":"resource-context-resource-name-declares-debugsupport","errorCode":null,"errorMessage":"Resource '{context.Resource.Name}' declares \"{debugSupport.LaunchConfigurationType}\" debug launch support (WithDebugSupport) but has no project metadata. The \"{debugSupport.LaunchConfigurationType}\" launch configuration type is reserved for .NET project resources; use a resource that carries IProjectMetadata or a different launch configuration type.","messagePattern":"Resource '(.+?)' declares \"(.+?)\" debug launch support \\(WithDebugSupport\\) but 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":"FailedToApplyEnvironmentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/ApplicationModel/ExecutableLaunchRecipe.cs","lineNumber":380,"sourceCode":"            resource.WorkingDirectory,\n            context.Decision.Mechanism,\n            executableArguments.Count > 0 ? executableArguments : null,\n            context.ExecutionConfiguration.EnvironmentVariables,\n            launchConfigurations,\n            displayArguments);\n    }\n\n    private static async Task<IReadOnlyList<JsonElement>> CreateLaunchConfigurationsAsync(ExecutableLaunchContext context)\n    {\n        if (context.Decision.DebugSupport is not { } debugSupport)\n        {\n            return [];\n        }\n\n        if (KnownLaunchConfigurationTypes.IsProject(debugSupport.LaunchConfigurationType) &&\n            !context.Resource.TryGetProjectMetadata(out _))\n        {\n            throw new FailedToApplyEnvironmentException(\n                $\"Resource '{context.Resource.Name}' declares \\\"{debugSupport.LaunchConfigurationType}\\\" debug launch support (WithDebugSupport) but has no project metadata. \" +\n                $\"The \\\"{debugSupport.LaunchConfigurationType}\\\" 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        var launchConfiguration = await ProduceLaunchConfigurationAsync(context, debugSupport).ConfigureAwait(false);\n        return [launchConfiguration];\n    }\n\n    internal static async Task<JsonElement> ProduceLaunchConfigurationAsync(\n        ExecutableLaunchContext context,\n        SupportsDebuggingAnnotation debugSupport)\n    {\n        try\n        {\n            var callbackContext = new LaunchConfigurationCallbackContext(\n                context.Decision.LaunchMode,\n                context.Resource,\n                context.ExecutionConfiguration.EnvironmentVariables.ToDictionary(","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ApplicationModel/ExecutableLaunchRecipe.cs#L362-L398","documentation":"WithDebugSupport with a project launch configuration type is only valid for resources carrying IProjectMetadata (i.e., .NET project resources). During CreateLaunchConfigurationsAsync, if a non-project resource declares a project launch configuration type, a FailedToApplyEnvironmentException is thrown with guidance to fix the declaration.","triggerScenarios":"Calling WithDebugSupport on a container or executable resource with the .NET project launch configuration type (KnownLaunchConfigurationTypes.IsProject true) while the resource has no ProjectResourceAnnotation/project metadata.","commonSituations":"Copy-pasted WithDebugSupport calls from project resources applied to containers/executables; generic helper extension applying debug support to arbitrary resources.","solutions":["Only call WithDebugSupport with a project launch configuration type on ProjectResource instances (AddProject results)","For non-project resources, use a non-project launch configuration type or drop the debug support call","Check the resource type in the extension helper and conditionally skip project-type debug support"],"exampleFix":"// before\nvar redis = builder.AddRedis(\"redis\");\nredis.WithDebugSupport(launchProfile, KnownLaunchConfigurationTypes.DotnetProject);\n// after\nvar api = builder.AddProject<Projects.Api>(\"api\");\napi.WithDebugSupport(launchProfile, KnownLaunchConfigurationTypes.DotnetProject);","handlingStrategy":"validation","validationCode":"bool isProjectType = resource is ProjectResource && resource.TryGetProjectMetadata(out _);\nif (debugSupport is not null && KnownLaunchConfigurationTypes.IsProject(debugSupport.LaunchConfigurationType) && !isProjectType)\n  throw new InvalidOperationException(\"Project debug launch support requires a project resource.\");","typeGuard":"bool IsProjectResource(IResource r) => r.Annotations.Any(a => a is IProjectMetadata);","tryCatchPattern":"try { await CreateLaunchConfigurationsAsync(context, ct); } catch (FailedToApplyEnvironmentException ex) when (ex.Message.Contains(\"WithDebugSupport\")) { /* retry without project debug support or fix resource type */ }","preventionTips":["Apply WithDebugSupport only to AddProject resources","Centralize debug-support registration in helpers that check the resource type","Use non-project launch configuration types for containers/executables"],"tags":["aspire","debugging","resources"],"backgroundTag":"incompatible-source-type","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"}