Skip to content

Calling Get-Help with the 'ShowWindow' parameter throws an error in the integrated console #570

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

Closed
rkeithhill opened this issue Nov 5, 2017 · 1 comment
Assignees
Labels
Issue-Bug A bug to squash.
Milestone

Comments

@rkeithhill
Copy link
Contributor

System Details

  • Operating system name and version:
    Windows 10 Enterprise Version 1607 (OS Build 14393.1066)
C:\> code -v

1.12.2
19222cdc84ce72202478ba1cec5cb557b71163de
C:\> $pseditor.EditorServicesVersion


Major  Minor  Build  Revision
-----  -----  -----  --------
1      0      0      0


C:\> code --list-extensions --show-versions

[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
C:\> $PSVersionTable


Name                           Value
----                           -----
PSVersion                      5.1.14393.1066
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.1066
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1


C:\>

Issue Description

Not sure if this is supposed to work, but ...

Calling Get-Help with the 'ShowWindow' parameter throws an error in the integrated console

C:\TEST> help Invoke-RestMethod -ShowWindow

Get-Help : Exception has been thrown by the target of an invocation.
At line:55 char:5
+     Get-Help @PSBoundParameters | more
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-Help], TargetInvocationException
    + FullyQualifiedErrorId : System.Reflection.TargetInvocationException,Microsoft.PowerShell.Commands.GetHelpCommand
[logs.zip](https://github.com/PowerShell/vscode-powershell/files/1007246/logs.zip)

Attached Logs

logs.zip

@rkeithhill
Copy link
Contributor Author

rkeithhill commented Nov 5, 2017

This is error because PSES returns null for $host.PrivateData (that's the default impl) and the PowerShell code is doing this:

https://github.com/PowerShell/PowerShell/blob/52569380c7d2bcf4060a6618e3cf81dcd320041c/src/Microsoft.PowerShell.GraphicalHost/commandHelpers/ShowCommandHelper.cs#L720-L736

Note that it is not null checking PrivateData. The fix is to simply return an empty PSObject.

BTW this is the error I see:

C:\Users\Keith> Get-Help Get-Process -ShowWindow
Get-Help : Exception has been thrown by the target of an invocation.
At line:1 char:1
+ Get-Help Get-Process -ShowWindow
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-Help], TargetInvocationException
    + FullyQualifiedErrorId : System.Reflection.TargetInvocationException,Microsoft.PowerShell.Commands.GetHelpCommand

C:\Users\Keith> $error[0] | fl * -Force


PSMessageDetails      :
Exception             : System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object
                        reference not set to an instance of an object.
                           at Microsoft.PowerShell.Commands.ShowCommandInternal.ShowCommandHelper.GetHostWindow(PSCmdlet cmdlet)
                           at Microsoft.PowerShell.Commands.Internal.HelpWindowHelper.ShowHelpWindow(PSObject helpObj, PSCmdlet cmdlet)
                           --- End of inner exception stack trace ---
                           at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
                           at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
                           at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
                           at Microsoft.PowerShell.Commands.GetHelpCommand.WriteObjectsOrShowOnlineHelp(HelpInfo helpInfo, Boolean showFullHelp)
                           at Microsoft.PowerShell.Commands.GetHelpCommand.ProcessRecord()
                           at System.Management.Automation.CommandProcessor.ProcessRecord()
TargetObject          :
CategoryInfo          : NotSpecified: (:) [Get-Help], TargetInvocationException
FullyQualifiedErrorId : System.Reflection.TargetInvocationException,Microsoft.PowerShell.Commands.GetHelpCommand
ErrorDetails          :
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}

NOTE: this fix will NOT help with the help window attaching to the desktop and not popping to the top. That is unfortunately. But given that PSES runs in a process without a window, we'd need to pass the VSCode hwnd (on Windows only) to PSES and then we could return that hwnd when this command asks for $host.PrivateData["Window"]. Then the window would appear on top. But I'll leave that for a separate issue and PR.

rkeithhill added a commit to rkeithhill/PowerShellEditorServices that referenced this issue Nov 5, 2017
This fix overrides the built-in PSHost.PrivateData property, which returns null.  The override instead returns an empty PSObject.  This fixes the Get-Help -ShowWindow scenario since Windows PowerShell will no longer get a NullRefEx on access the host PrivateData property without doing a null check.  Since PrivateData["Window"] will still return null, PowerShell will show the dialog with the desktop as the parent window. IOW this PR does not fix the issue with the help window not appearing on top.  It simply fixes the error you get in PSIC.
@rkeithhill rkeithhill added this to the 1.5.1 milestone Nov 5, 2017
@daviwil daviwil closed this as completed in c762ff7 Nov 8, 2017
TylerLeonhardt pushed a commit to TylerLeonhardt/PowerShellEditorServices that referenced this issue Feb 26, 2019
Fix PowerShell#532: DEVPATH env variable not being set for integrated console
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

1 participant