Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Windows.Forms Dialogs Don't Open In Debugger #410

Closed
sunmorgus opened this issue Dec 22, 2016 · 16 comments
Closed

System.Windows.Forms Dialogs Don't Open In Debugger #410

sunmorgus opened this issue Dec 22, 2016 · 16 comments
Labels
Issue-Bug A bug to squash.

Comments

@sunmorgus
Copy link

Please fill in these details so that we can help you!

System Details

  • Operating system name and version: Windows 10 x64
  • VS Code version: 1.8.1
  • PowerShell extension version: 0.8.0
  • Output from $PSVersionTable:
Name                           Value
----                           -----
PSVersion                      5.0.10586.672
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.10586.672
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

Using the below script in the debugger, the dialog window does not appear, and the debugger crashes.

function Get-FileName($initialDirectory){   
    [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |  Out-Null

    $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
    $OpenFileDialog.initialDirectory = $initialDirectory
    $OpenFileDialog.filter = "All files (*.*)| *.*"
    $OpenFileDialog.ShowDialog() | Out-Null
    $OpenFileDialog.filename
}

Attached Logs

vscode-powershell - Copy.txt
EditorServices - Copy.txt

@daviwil
Copy link
Contributor

daviwil commented Dec 22, 2016

Hmm, haven't seen this before. I'll take a look!

@daviwil daviwil added the Issue-Bug A bug to squash. label Dec 22, 2016
@sunmorgus
Copy link
Author

A little more info... I changed the code to this (using Add-Type instead of [System.Reflection...]) and debugged through it... it won't progress past the ".ShowDialog()" and never actually shows the dialog.

function Get-FileName($initialDirectory){   
    Add-Type -AssemblyName System.Windows.Forms

    $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
    $OpenFileDialog.initialDirectory = $initialDirectory
    $OpenFileDialog.filter = "All files (*.*)| *.*"
    $result = $OpenFileDialog.ShowDialog()
    if($result -eq "Cancel"){
        break
    }
    return $OpenFileDialog.filename
}

$path = Get-FileName "c:\aaa"

I do know that some of the windows forms stuff works, because I can use the below code to pop up a message balloon:

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$message = "test"
#Notification Balloon
#load Windows Forms and drawing assemblies           
#define an icon image pulled from PowerShell.exe            
$icon=[system.drawing.icon]::ExtractAssociatedIcon((join-path $pshome powershell.exe)) 

$objNotifyIcon = New-Object System.Windows.Forms.NotifyIcon 

$objNotifyIcon.Icon = $icon
$objNotifyIcon.BalloonTipIcon = "Info"  #can be Info, Warn, or Error
$objNotifyIcon.BalloonTipText = "$message" 
$objNotifyIcon.BalloonTipTitle = "Info"

$objNotifyIcon.Visible = $True 
$objNotifyIcon.ShowBalloonTip(10000) #time in seconds to show notification

@sunmorgus
Copy link
Author

A suggestion for fixing this (maybe a quick fix?)... for C# projects, there is an attribute in the launch.json called externalConsole (see screenshot below) that allows you to debug in an external window. Not sure if that would be possible for powershell, but maybe worth looking at.

image

@daviwil
Copy link
Contributor

daviwil commented Jan 18, 2017

Unfortunately this setting will not make a difference, it's more of an issue with the code in our debug adapter. I still haven't got a chance to look at this but I will as soon as I ship 0.9.0. Sorry for the delay!

@daviwil daviwil added this to the 0.9.1 milestone Jan 18, 2017
@daviwil daviwil modified the milestones: 0.9.1, 0.10.1, 0.10.2 Mar 14, 2017
@daviwil daviwil modified the milestones: 0.10.2, 0.11.1 Mar 24, 2017
@daviwil daviwil modified the milestones: Next Patch Update, Next Feature Update Apr 6, 2017
@daviwil daviwil modified the milestones: April 2017, May 2017 May 8, 2017
@daviwil daviwil modified the milestones: May 2017, July 2017 Jun 1, 2017
@daviwil daviwil modified the milestones: July 2017, Future Oct 26, 2017
@yltlatl
Copy link

yltlatl commented Mar 15, 2018

Hi, is there any plan to fix this? Working on a project that uses this a lot, and it is a pain switching over to ISE to debug...

@moymike
Copy link

moymike commented Mar 15, 2018

I ran into this myself on a longtime running script that prompts for user/password:
$Host.ui.PromptForCredential($WindowTitle, $Prompt, $UserName, "", $CredentialType, $ValidateOption)

On ISE or commandline this creates a windows box that prompts. With the current terminal, it prompts in plain text.

@rkeithhill
Copy link
Contributor

rkeithhill commented Mar 20, 2018

I think @sunmorgus has a reasonable idea. You can work-around this by launching your script in an external console with a Wait-Debugger at the start, use VSCode to attach to the process and then debug it. However, we should provide an easier way to do this i.e. debug via a new, external console.

@TylerLeonhardt TylerLeonhardt modified the milestone: Future May 24, 2018
@SuHwak
Copy link

SuHwak commented Jun 12, 2018

I am in the process of moving over from ISE to VS Code (to leverage git), only to come across this problem. @rkeithhill Do you have a step-by-step for me?

@rkeithhill
Copy link
Contributor

rkeithhill commented Jun 13, 2018

I can't repro the original issue. The OpenFile dialog opens for me and returns the selected file. If you have a repro post it here otherwise, I'm going to close this issue.

@SuHwak
Copy link

SuHwak commented Jun 13, 2018

Below is the code I'm working with (mostly not my own), which works great in PowerShell_ISE, as well as a regular PS prompt.

I just found that if debugging with the option to "Launch current file in temporary console" it works too, however, when using the default "Launch current file" it executes in the integrated console and it just hangs indefinitely.

Using the temporary console doesn't work for debugging blocks or lines of code of course.

Is there a logfile for VS Code? I'm running the latest version 1.24.0 on Windows 10 1803.

Function Get-FileName($InitialDirectory, $Filename, $FilenameDescription ,$FileType, $FileTypeDescription, $Title)
{  
 [Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null

 if (!$Filename) 
    {
    $Filename = "*"
    $FilenameDescription = "Any file name of type"
    }

 if (!$FileType) 
    {
    $FileType = "*"
    $FileTypeDescription = "any"
    }
 

 $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
 $OpenFileDialog.Title = $Title
 $OpenFileDialog.initialDirectory = $initialDirectory
 $OpenFileDialog.filter = "$($FilenameDescription) $($FileTypeDescription) ($($Filename).$($FileType)) | $($Filename).$($FileType)"
 $OpenFileDialog.ShowDialog() | Out-Null
 $OpenFileDialog.filename
} #end function Get-FileName

$PickedFile = Get-FileName

Write-Host $PickedFile

@rjmholt
Copy link
Contributor

rjmholt commented Jun 13, 2018

@SuHwak you should be able to find the log files by following these instructions.

The other way to do it is to go into VSCode and use Ctrl+Shift+P to bring up the VSCode command palette. In there, if you type "logs" you should get presented with an option like "PowerShell: Open PowerShell Extension Logs Folder". That will open the folder up for you in VSCode.

@SuHwak
Copy link

SuHwak commented Jun 14, 2018

Thank you @rjmholt, however, the logs don't show anything because the console just hangs (probably waiting for the result), and I have to force close the terminal. Any other suggestions?

@rjmholt
Copy link
Contributor

rjmholt commented Jun 14, 2018

@SuHwak the logs should exist if the integrated console started — are you saying there are no logs at all, or that they just drop off when you run the hanging code and there's no further info?

@TylerLeonhardt
Copy link
Member

@SuHwak IIRC there is a bug in Electron where dialogs were showing up behind VSCode. Can you double check that the dialog you're looking for isn't behind VSCode.

@SuHwak
Copy link

SuHwak commented Jun 15, 2018

@rjmholt @tylerl0706 It was indeed hiding stealthily behind VS Code window all that time. It didn't create a taskbar item either or else I would have noticed earlier! Thank you, I can now revert back (thanks to Git) :)

@TylerLeonhardt
Copy link
Member

Here's the issue on VSCode.

You may want to reply in that issue that this is the case.

Im going to close this in favor of that since there's nothing we can do. If you think we do have a problem here, feel free to reach out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug A bug to squash.
Projects
None yet
Development

No branches or pull requests

8 participants