Title: Ignore file path validation on Set-PSBreakpoint for attach scenarios · Issue #2243 · PowerShell/PowerShellEditorServices · GitHub
Open Graph Title: Ignore file path validation on Set-PSBreakpoint for attach scenarios · Issue #2243 · PowerShell/PowerShellEditorServices
X Title: Ignore file path validation on Set-PSBreakpoint for attach scenarios · Issue #2243 · PowerShell/PowerShellEditorServices
Description: Prerequisites I have written a descriptive issue title. I have searched all issues to ensure it has not already been requested. Summary I would live to avoid the file path validation that occurs when PSES sets a breakpoint on PowerShell ...
Open Graph Description: Prerequisites I have written a descriptive issue title. I have searched all issues to ensure it has not already been requested. Summary I would live to avoid the file path validation that occurs wh...
X Description: Prerequisites I have written a descriptive issue title. I have searched all issues to ensure it has not already been requested. Summary I would live to avoid the file path validation that occurs wh...
Opengraph URL: https://github.com/PowerShell/PowerShellEditorServices/issues/2243
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Ignore file path validation on Set-PSBreakpoint for attach scenarios","articleBody":"### Prerequisites\n\n- [x] I have written a descriptive issue title.\n- [x] I have searched all [issues](https://github.com/PowerShell/PowerShellEditorServices/issues?q=is%3Aissue) to ensure it has not already been requested.\n\n### Summary\n\nI would live to avoid the file path validation that occurs when PSES sets a breakpoint on PowerShell 5.1. There is an API split where PowerShell 5.1 uses the [Set-PSBreakpoint](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/set-psbreakpoint?view=powershell-7.5) to set a line breakpoint whereas 7.x uses the PSRemoting based `__Set-PSBreakpoint` command which is treated specially by the server. The 7.x API does not do any validation on the file path whereas `Set-PSBreakpoint` used by 5.1 will fail if the path does not exist.\n\nFor an attach scenario, PSES could be attaching itself to a runspace where the scriptblocks are set to a path that may or may not exist, e.g.\n\n```powershell\n$sbk = [System.Management.Automation.Language.Parser]::ParseInput(\n '$PSCommandPath',\n 'foo.ps1',\n [ref]$null,\n [ref]$null).GetScriptBlock()\n\n\u0026 $sbk # foo.ps1\n```\n\nIn the above case the script could be multiple lines and while 7.x will be able to set breakpoints on any of lines by targeting `foo.ps1` as the script, WinPS 5.1 will fail because `foo.ps1` does not exist.\n\n### Proposed Design\n\nWe can implement this by not calling `Set-PSBreakpoint` in the 5.1 fallback path.\n\nhttps://github.com/PowerShell/PowerShellEditorServices/blob/6bb322ec2150ed341991ffc7db7180db7a49539d/src/PowerShellEditorServices/Services/DebugAdapter/BreakpointService.cs#L117-L120\n\nInstead we could do something like\n\n```csharp\nnamespace Microsoft.PowerShell.EditorServices.Services\n{\n internal class BreakpointService\n {\n private readonly string _setPsBreakpointScript = \"\"\"\n [CmdletBinding()]\n param (\n [Parameter(Mandatory)]\n [string]\n $Script,\n\n [Parameter()]\n [int]\n $Line,\n\n [Parameter()]\n [int]\n $Column,\n\n [Parameter()]\n [ScriptBlock]\n $Action\n )\n\n $lineCtor = [System.Management.Automation.LineBreakpoint].GetConstructor(\n [System.Reflection.BindingFlags]'NonPublic, Instance',\n $null,\n [type[]]@([string], [int], [int], [scriptblock]),\n $null)\n\n $b = $lineCtor.Invoke(@($Script, $Line, $Column, $Action))\n [Runspace]::DefaultRunspace.Debugger.SetBreakpoints(\n [System.Management.Automation.Breakpoint[]]@($b))\n\n $b\n \"\"\";\n\n ...\n\n // In SetBreakpointsAsync\n // Instead of psCommand.AddCommand(...) do this instead\n psCommand\n .AddScript(_setPsBreakpointScript, useLocalScope: true)\n .AddParameter(\"Script\", escapedScriptPath)\n .AddParameter(\"Line\", breakpoint.LineNumber);\n```\n\nThis uses a small bit of reflection to build the [LineBreakpoint](https://learn.microsoft.com/en-us/dotnet/api/system.management.automation.linebreakpoint?view=powershellsdk-7.4.0) object which did not have a public constructor in 5.1. While reflection isn't great, 5.1 is mostly an EOL product and newer versions will be using the public API so we shouldn't have any future breakage issues.","author":{"url":"https://github.com/jborean93","@type":"Person","name":"jborean93"},"datePublished":"2025-07-23T03:53:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/2243/PowerShellEditorServices/issues/2243"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:997154a5-90c2-ff48-36da-c6cc61d1207c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B0D0:7C839:161847A:1F91DA1:6A58D149 |
| html-safe-nonce | eff3068be690a20aaf0bfb460cba1579c354142b5aef7100ba11e506a109160c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMEQwOjdDODM5OjE2MTg0N0E6MUY5MURBMTo2QTU4RDE0OSIsInZpc2l0b3JfaWQiOiI3ODM3NjUwODY0MDY4Njc3OTYxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 2faf5e058ad3ab543b55402dc02d5c21985b67148fc147bbcd8ff8117601eeda |
| hovercard-subject-tag | issue:3254745074 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShellEditorServices/2243/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8c28193a30567955defc0d048cd5d8232286d343d41a622b8328c2b69261357e/PowerShell/PowerShellEditorServices/issues/2243 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8c28193a30567955defc0d048cd5d8232286d343d41a622b8328c2b69261357e/PowerShell/PowerShellEditorServices/issues/2243 |
| og:image:alt | Prerequisites I have written a descriptive issue title. I have searched all issues to ensure it has not already been requested. Summary I would live to avoid the file path validation that occurs wh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jborean93 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f2a0c7865178af3d91dd9f13b0cdfc3c73a2529c873d2780bb4c01271a57ec6 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShellEditorServices git https://github.com/PowerShell/PowerShellEditorServices.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 36031537 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShellEditorServices |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36031537 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShellEditorServices |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8aae7b8d6caacacf5c66eaeb2702d8dc88d85b4a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width