{"record":{"id":"816953a4b5c78544","repo":"microsoft/aspire","slug":"cannot-configure-debugging-python-entrypoint-annotation-not","errorCode":null,"errorMessage":"Cannot configure debugging: Python entrypoint annotation not found.","messagePattern":"Cannot configure debugging: Python entrypoint annotation not found\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs","lineNumber":935,"sourceCode":"    /// </para>\n    /// <para>\n    /// The debug configuration includes the Python interpreter path from the virtual environment,\n    /// the program or module to debug, and appropriate launch settings.\n    /// </para>\n    /// </remarks>\n    [AspireExport]\n    public static IResourceBuilder<T> WithDebugging<T>(\n        this IResourceBuilder<T> builder) where T : PythonAppResource\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n\n        // Add the annotation that marks this resource as debuggable\n        builder.WithAnnotation(new PythonExecutableDebuggableAnnotation());\n\n        // Get the entrypoint annotation to determine how to configure debugging\n        if (!builder.Resource.TryGetLastAnnotation<PythonEntrypointAnnotation>(out var entrypointAnnotation))\n        {\n            throw new InvalidOperationException(\"Cannot configure debugging: Python entrypoint annotation not found.\");\n        }\n\n        var entrypointType = entrypointAnnotation.Type;\n        var entrypoint = entrypointAnnotation.Entrypoint;\n\n        builder.WithDebugSupport(\n            mode =>\n            {\n                // Compute paths inside the lambda so a later WithWorkingDirectory(...) override is respected.\n                var workingDirectory = builder.Resource.WorkingDirectory;\n\n                string programPath;\n                string module;\n\n                if (entrypointType == EntrypointType.Script)\n                {\n                    programPath = Path.GetFullPath(entrypoint, workingDirectory);\n                    module = string.Empty;","sourceCodeStart":917,"sourceCodeEnd":953,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs#L917-L953","documentation":"WithDebugging attaches PythonExecutableDebuggableAnnotation and then reads PythonEntrypointAnnotation to know whether the entrypoint is a script, module, or executable so it can wire debug support. Without that annotation the debug configuration cannot proceed, so it throws InvalidOperationException.","triggerScenarios":"Calling WithDebugging on a Python resource that was not created through AddPythonApp/AddPythonExecutable (no PythonEntrypointAnnotation), or on the wrong builder instance.","commonSituations":"Manually built PythonResource instances; chaining WithDebugging before the entrypoint-configuring call; copying sample code onto a resource of a different type.","solutions":["Configure the app via AddPythonApp or AddPythonExecutable before calling WithDebugging.","Verify the chain targets the same resource that has the entrypoint annotation.","If the resource is manual, add a PythonEntrypointAnnotation with correct EntrypointType/Entrypoint first.","Reorder builder calls so entrypoint configuration precedes debugging configuration."],"exampleFix":"// before\nvar py = builder.AddPythonResource(\"app\");\npy.WithDebugging();\n// after\nvar py = builder.AddPythonApp(\"app\", \"main.py\");\npy.WithDebugging();","handlingStrategy":"type-guard","validationCode":"bool canDebug = pyApp.Resource.HasAnnotation<PythonEntrypointAnnotation>();","typeGuard":"static bool IsDebuggableCandidate(IResource resource) => resource.TryGetLastAnnotation<PythonEntrypointAnnotation>(out _);","tryCatchPattern":"try\n{\n    pyApp.WithDebugging();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Cannot configure debugging\"))\n{\n    logger.LogError(ex, \"WithDebugging requires an entrypoint from AddPythonApp/AddPythonExecutable.\");\n}","preventionTips":["Create Python resources via AddPythonApp/AddPythonExecutable before enabling debugging.","Verify WithDebugging is chained on the same builder as entrypoint setup.","Order calls: create app, then WithVirtualEnvironment, then WithDebugging."],"tags":["csharp","aspire","python","debugging","missing-annotation"],"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"}