microsoft/DbgShell

Get-Help -ShowWindow gives an error

dronkoff opened this issue · 2 comments

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

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

Thanks for reporting this! I don't think I've ever used -ShowWindow, so I would never have found it on my own.

I suspect this is because DbgShell's PSHost does not override the PrivateData property (so returns null):

// Microsoft.PowerShell.Commands.ShowCommandInternal.ShowCommandHelper
internal static Window GetHostWindow(PSCmdlet cmdlet)
{
	PSPropertyInfo pSPropertyInfo = cmdlet.Host.PrivateData.Properties["Window"];

The type of PrivateData is PSObject... I wonder what sort of shape that thing should be. Will need to look at a "real" PSHost implementation to see.

In console host it returns

PS C:\Users\vdronov> (Get-Host).PrivateData | Get-Member

   TypeName: Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy

Name                    MemberType Definition
----                    ---------- ----------
Equals                  Method     bool Equals(System.Object obj)
GetHashCode             Method     int GetHashCode()
GetType                 Method     type GetType()
ToString                Method     string ToString()
DebugBackgroundColor    Property   System.ConsoleColor DebugBackgroundColor {get;set;}
DebugForegroundColor    Property   System.ConsoleColor DebugForegroundColor {get;set;}
ErrorBackgroundColor    Property   System.ConsoleColor ErrorBackgroundColor {get;set;}
ErrorForegroundColor    Property   System.ConsoleColor ErrorForegroundColor {get;set;}
ProgressBackgroundColor Property   System.ConsoleColor ProgressBackgroundColor {get;set;}
ProgressForegroundColor Property   System.ConsoleColor ProgressForegroundColor {get;set;}
VerboseBackgroundColor  Property   System.ConsoleColor VerboseBackgroundColor {get;set;}
VerboseForegroundColor  Property   System.ConsoleColor VerboseForegroundColor {get;set;}
WarningBackgroundColor  Property   System.ConsoleColor WarningBackgroundColor {get;set;}
WarningForegroundColor  Property   System.ConsoleColor WarningForegroundColor {get;set;}

I use it to colorize error messages with this code written in profile.ps1.
I've added if statement because DbgShell returns null :-)

$a = (Get-Host).PrivateData
if(-not $a -eq $null)
{
    $a.ErrorBackgroundColor = "red"
    $a.ErrorForegroundColor = "white"
}