vscode-powershell: Debugger hangs when `System.Windows.Forms` objects are used

1623418243-1001617c-c46c-460d-a567-6024e60e18a91623416489171.zip

System Details Output

VSCode version: 1.57.0 b4c1bd0a9b03c749ea011b06c6d2676c8091a70c x64

VSCode extensions:

ms-vscode.powershell@2021.5.1 vscodevim.vim@1.21.1

PSES version: 2.4.3.0

PowerShell version:

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0


System Info:
Edition	Windows 10 Home
Version	20H2
Installed on	‎03/‎10/‎2020
OS build	19042.1052
Serial number	MP1A8Y87
Experience	Windows Feature Experience Pack 120.2212.2020.0

Issue Description

Visual Studio was installed and ran for some days without problems. I saw a message indicating that an update was applied. After that I got the problem described below. Script is:

Add-Type -AssemblyName 'System.Windows.Forms'

$contextFilmStripAlbumPictureBoxMenuStrip = New-Object System.Windows.Forms.ContextMenuStrip
$null = $contextFilmStripAlbumPictureBoxMenuStrip.Items.Add("Single larger picture slideshow")
Write-Host 'Hello world'

I set a breakpoint on line 4 ($contextFilmStripAlbumPictureBoxMenuStrip = New-Object System.Windows.Forms.ContextMenuStrip) Start debugging with F5. Stops on line 4 with highlight. Press F10 and debugger appears hung. (Run menu has grayed out the F10 and F11). These keys do not work. On occasions pressing F5 then ‘Hello World’ appears on terminal. Terminal prompt> is not hung.

Expected Behaviour

Expected using F10 to step over each line of code in script.

Actual Behaviour

After a number of steps Visual Studio hangs. F10,F11 are greyed out in the Run menu and the keys do not work

Attached Logs

Set to diagnostic and supplied.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 22 (10 by maintainers)

Most upvoted comments

Super helpful, thanks @youngr137! Sometimes this feels like a game of whack-a-mole: fix one problem and another crops up 😬

I probably confused people looking at issue #3394 with my comment there yesterday as they should have been here for this issue. Essentially the issue raised appears to be fixed by the preview v2021.8.1. I am able to run scripts with System.Windows.Form objects in them and step through using F10, F11 etc. There is a remaining problem (which I don’t think is the same as issue #2821) where the script can’t be re-run (or any PS script run). The script fails to start and the PowerShell Extension Logs show a timeout. This is a small snippet from the log: 11/08/2021 10:55:38 [VERBOSE] - Connected to socket! 11/08/2021 11:17:52 [VERBOSE] - Connecting to pipe: \.\pipe\PSES_cltnlzc4.cdi 11/08/2021 11:17:52 [VERBOSE] - Debug configuration: {“name”:“PowerShell Launch Current File”,“type”:“PowerShell”,“request”:“launch”,“script”:“c:\Users\roger\Documents\cmds\testit\generateThumbnailsInSourceTree.ps1”,“args”:[“-debug -testDir C:\tmp\m\sourcePics -checkOnly”],“cwd”:“c:\Users\roger\Documents\cmds\testit\generateThumbnailsInSourceTree.ps1”,“__configurationTarget”:5,“createTemporaryIntegratedConsole”:false,“internalConsoleOptions”:“neverOpen”} 11/08/2021 11:18:22 [ERROR] - Error on Debug Adapter: Error: connect ETIMEDOUT \.\pipe\PSES_cltnlzc4.cdi The line a 11/08/2021 10:55:38 is the last thing logged when I ran a script successfully. Then at 11/08/2021 11:17:52 I attempted to start a new script and the timeout occurs. I looked at the PowerShell Editor Services logs and the last thing logged is at 11:01:29 and these are errors (presumably from running the first script) [Error - 11:01:29] Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Exception occurred while executing debugger command | [Error - 11:01:29] Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Execution of the following command(s) completed with errors:

Get-Variable -Scope 1

| [Warn - 11:01:29] Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Runtime exception occurred while executing command |

Looking back through this log file the first error looks like: [Warn - 10:55:40] Microsoft.PowerShell.EditorServices.Services.WorkspaceService: Failed to get file for fileUri: ‘untitled:Untitled-1’ |

The file Untitled-1 does not exist but I am guessing gets created when you use File->New File. I had done this some days ago and just closed the tab that gets created. It does show up in the BREAKPOINTS section on the left of Visual Studio with 2 breakpoints. However having removed the breakpoints I still get problems on restarting/starting a script after a successful run.

I stopped and restarted Visual Studio Here are the logs from a test to run and rerun a script testTextbox.ps1. I started it at 13:39:13 and after stepping through a couple of lines and then F5 I exited the program and started it again at 13:40:25. The extension log shows a timeout and the Editor Services log shows error from the first run of testTextbox.ps1 so I am guessing the problem is there? 1628685473-ec06d506-16b0-4a93-b6a2-2b51f54fbdb41628685455792.zip

This issue is I think now raised as issue #3505

I just tried and it worked as expected, not the first time after the VSIX was loaded because it hung on the DisplayDialog() method call by not displaying the dialog window. After I restarted VSCode it started working fine again being to able to stop at breakpoints after windows.form was invoked before DisplayDialog, as well as displaying the proper dialog thereafter.

If there is anything further you need from me please let me know. I’m UK based but retired so my time is my own. Roger

On Mon, 14 Jun 2021 at 21:39, Andrew Schwartzmeyer @.***> wrote:

Interesting. It seems to be a protocol issue because as you say the PowerShell process itself is correctly debugging, it’s just that the information that needs to be relayed from the process to the DAP server underneath VS Code. We’ll need to repro this internally to make any headway, and the DAP is actually being worked on by @rjmholt https://github.com/rjmholt so perhaps this bug will be fixed by the rework in PowerShell/PowerShellEditorServices#1459 https://github.com/PowerShell/PowerShellEditorServices/pull/1459

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/PowerShell/vscode-powershell/issues/3410#issuecomment-860976636, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUMZMC7YONZKABWSPVW23HDTSZSJLANCNFSM46QZQLSA .