Registry Mirror
Skip to content

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

Closed

Description

@sunmorgus

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

Activity

  1. daviwil commented on Dec 22, 2016

    @daviwil
    Contributor

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

  2. sunmorgus commented on Jan 3, 2017

    @sunmorgus
    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
    
  3. sunmorgus commented on Jan 18, 2017

    @sunmorgus
    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

  4. daviwil commented on Jan 18, 2017

    @daviwil
    Contributor

    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!

  5. added this to the milestone on Jan 18, 2017
  6. modified the milestones: , 0.10.1, on Mar 14, 2017
  7. removed this from the milestone on Mar 24, 2017
  8. 19 remaining items

  9. rkeithhill commented on Mar 20, 2018

    @rkeithhill
    Contributor

    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.

  10. modified the milestone: on May 24, 2018
  11. SuHwak commented on Jun 12, 2018

    @SuHwak

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

  12. rkeithhill commented on Jun 13, 2018

    @rkeithhill
    Contributor

    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.

  13. SuHwak commented on Jun 13, 2018

    @SuHwak

    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
    
  14. rjmholt commented on Jun 13, 2018

    @rjmholt
    Contributor

    SuHwak (@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.

  15. SuHwak commented on Jun 14, 2018

    @SuHwak

    Thank you Rob Holt (@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?

  16. rjmholt commented on Jun 14, 2018

    @rjmholt
    Contributor

    SuHwak (@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?

  17. TylerLeonhardt commented on Jun 14, 2018

    @TylerLeonhardt
    Member

    SuHwak (@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.

  18. SuHwak commented on Jun 15, 2018

    @SuHwak

    Rob Holt (@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) :)

  19. TylerLeonhardt commented on Jun 15, 2018

    @TylerLeonhardt
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions