question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Debugger hangs when `System.Windows.Forms` objects are used

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:22 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
andschwacommented, Aug 11, 2021

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

1reaction
youngr137commented, Aug 11, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Preventing Hangs in Windows Applications - Win32 apps
Windows automatically detects, collects debug information, and optionally terminates or restarts hung applications. Otherwise, the user might ...
Read more >
7 Debugging Techniques for when your .NET application ...
7 Debugging Techniques for when your .NET application Freezes (hangs) · 1. Attach to the frozen process with Visual Studio · 2. Attach...
Read more >
Visual Studio 2022 debugger hangs when debugging C# ...
If you do, if you turn them off (Tools->Options->Debugging->Enable Diagnostics Tools While Debugging) does it repro? Ryan Molden Software Engineer Microsoft ...
Read more >
Application freezes outside of Visual Studio. While starting ...
Currently I use the System.Windows.Forms.Timer and some locks but there is no improvement. Okay I used WinDbg to get some informations. Edit: 14.06.2012....
Read more >
Find the Cause of a UI Freeze | dotTrace Documentation
It contains the Main application thread, the Finalizer thread used by runtime for finalizing objects (does no work in our application), ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found