Skip to content

'Safe handle has been closed' when stopping debugger while in a dynamicparam section in v2.2 #3751

Open
@fsackur

Description

@fsackur

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.

Exception report

Last 200 Keys:

<omitted irrelevant keystrokes>
 f o o Spacebar - b Tab

### Exception

System.ObjectDisposedException: Safe handle has been closed
   at System.Threading.WaitHandle.WaitMultiple(WaitHandle[] waitHandles, Int32 millisecondsTimeout, Boolean exitContext, Boolean WaitAll)
   at System.Threading.WaitHandle.WaitAny(WaitHandle[] waitHandles, Int32 millisecondsTimeout, Boolean exitContext)
   at Microsoft.PowerShell.PSConsoleReadLine.ReadKey()
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken, Nullable`1 lastRunStatus)

Screenshot

N/A

Environment data

PS Version: 5.1.19041.1320
PS HostName: Visual Studio Code Host
PSReadLine Version: 2.2.0-beta4
PSReadLine EditMode: Windows
OS: 10.0.19041.1 (WinBuild.160101.0800)
BufferWidth: 227
BufferHeight: 28

Steps to reproduce

  • Use VS Code with PowerShell Preview 2021.12.0 extension
  • Create a function with dynamic parameters, e.g.:
function foo
{
    [CmdletBinding()]
    param ()

    dynamicparam
    {
        $DynParams = [Management.Automation.RuntimeDefinedParameterDictionary]::new()

        $DynParam = [Management.Automation.RuntimeDefinedParameter]::new(
            'bar',
            [string],
            [Collections.ObjectModel.Collection[System.Attribute]]::new()
        )

        $DynParams.Add($DynParam.Name, $DynParam)

        return $DynParams
    }
}
  • Put a breakpoint within the dynamicparam block and start an interactive session
  • Invoke the dynamic parameter with foo - and hit <tab>
  • Debugger stops in the dynamicparam block, as expected
  • Stop the debugger with <Ctrl-F5>
  • Integrated console returns, but shows error message

Expected behavior

No exception

Actual behavior

Error shown

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Wishlist

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions