Skip to content

Commit 6691f08

Browse files
committed
Add fallback to Set-PSBreakpoint in case reflection can't find ctor
1 parent 7f62aac commit 6691f08

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/BreakpointService.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ namespace Microsoft.PowerShell.EditorServices.Services
1818
{
1919
internal class BreakpointService
2020
{
21+
/// <summary>
22+
/// Code used on WinPS 5.1 to set breakpoints without Script path validation.
23+
/// It uses reflection because the APIs were not public until 7.0 but just in
24+
/// case something changes it has a fallback to Set-PSBreakpoint.
25+
/// </summary>
2126
private const string _setPSBreakpointLegacy = @"
2227
[CmdletBinding(DefaultParameterSetName = 'Line')]
2328
param (
@@ -49,6 +54,12 @@ internal class BreakpointService
4954
$null,
5055
[type[]]@([string], [System.Management.Automation.WildcardPattern], [string], [ScriptBlock]),
5156
$null)
57+
58+
if (-not $cmdCtor) {
59+
Microsoft.PowerShell.Utility\Set-PSBreakpoint @PSBoundParameters
60+
return
61+
}
62+
5263
$pattern = [System.Management.Automation.WildcardPattern]::Get(
5364
$Command,
5465
[System.Management.Automation.WildcardOptions]'Compiled, IgnoreCase')
@@ -60,6 +71,12 @@ internal class BreakpointService
6071
$null,
6172
[type[]]@([string], [int], [int], [ScriptBlock]),
6273
$null)
74+
75+
if (-not $lineCtor) {
76+
Microsoft.PowerShell.Utility\Set-PSBreakpoint @PSBoundParameters
77+
return
78+
}
79+
6380
$b = $lineCtor.Invoke(@($Script, $Line, $Column, $Action))
6481
}
6582

0 commit comments

Comments
 (0)