ConsoleGuiTools icon indicating copy to clipboard operation
ConsoleGuiTools copied to clipboard

OCGV: Out-ConsoleGridView does not accept XML data

Open jasper-zanjani opened this issue 5 years ago • 10 comments
trafficstars

While manipulating XML data and testing Out-ConsoleGridView (Powershell 7.0.0 on Windows 10.0.19603), I noticed that the cmdlet appears to demand data of a certain datatype. For testing, a sample XML file can be found here.

[xml]$xml = Get-Content '.\sample.xml'

Tabular output from $xml can be viewed in the terminal

$xml.catalog.book

Output

id           : bk101
author       : Gambardella, Matthew
title        : XML Developer's Guide
genre        : Computer
price        : 44.95
publish_date : 2000-10-01
description  : An in-depth look at creating applications 
                     with XML.

id           : bk102
...

Piping to Out-GridView produces expected output

$xml.catalog.book | Out-GridView

out-gridview

However, piping to Out-ConsoleGridView produces an error

$xml.catalog.book | Out-ConsoleGridView

out-consolegridview The BaseType of $xml.catalog.book is System.Array

jasper-zanjani avatar May 05 '20 18:05 jasper-zanjani

hmm I can't seem to repro this...

image

I had it repro'ing once but that PowerShell instance seemed to be corrupted in some way...

It might be that the next version of gui.cs that we depend on will have more stability here.

TylerLeonhardt avatar May 06 '20 23:05 TylerLeonhardt

I just updated to 7.0.1 and I am getting the same error, any new ideas?

jasper-zanjani avatar May 18 '20 05:05 jasper-zanjani

Can you paste the output of Get-Error?

TylerLeonhardt avatar May 18 '20 14:05 TylerLeonhardt

gentle ping on this

TylerLeonhardt avatar Aug 28 '20 20:08 TylerLeonhardt

I just went through the same steps, creating an XML object from the same test file above.

jaspe PS> $data.catalog.book | Out-ConsoleGridView
Out-ConsoleGridView: Length cannot be less than zero. (Parameter 'length')
Exception             :
    Type       : System.ArgumentOutOfRangeException
    Message    : Length cannot be less than zero. (Parameter 'length')
    ParamName  : length
    TargetSite :
        Name          : Substring
        DeclaringType : string
        MemberType    : Method
        Module        : System.Private.CoreLib.dll
    StackTrace :
   at System.String.Substring(Int32 startIndex, Int32 length)
   at OutGridView.Cmdlet.ConsoleGui.GetPaddedString(List`1 strings, Int32 offset) in
D:\a\1\s\src\Microsoft.PowerShell.ConsoleGuiTools\ConsoleGui.cs:line 320
   at OutGridView.Cmdlet.ConsoleGui.Start(ApplicationData applicationData) in
D:\a\1\s\src\Microsoft.PowerShell.ConsoleGuiTools\ConsoleGui.cs:line 152
   at OutGridView.Cmdlet.OutConsoleGridViewCmdletCommand.EndProcessing() in
D:\a\1\s\src\Microsoft.PowerShell.ConsoleGuiTools\OutConsoleGridviewCmdletCommand.cs:line 143
   at System.Management.Automation.CommandProcessorBase.Complete()
    Source     : System.Private.CoreLib
    HResult    : -2146233086
CategoryInfo          : NotSpecified: (:) [Out-ConsoleGridView], ArgumentOutOfRangeException
FullyQualifiedErrorId : System.ArgumentOutOfRangeException,OutGridView.Cmdlet.OutConsoleGridViewCmdletCommand
InvocationInfo        :
    MyCommand        : Out-ConsoleGridView
    ScriptLineNumber : 1
    OffsetInLine     : 22
    HistoryId        : 15
    Line             : $data.catalog.book | Out-ConsoleGridView
    PositionMessage  : At line:1 char:22
                       + $data.catalog.book | Out-ConsoleGridView
                       +                      ~~~~~~~~~~~~~~~~~~~
    InvocationName   : Out-ConsoleGridView
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

For the record:

jaspe PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.1
PSEdition                      Core
GitCommitId                    7.0.1
OS                             Microsoft Windows 10.0.20201
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

And the data object certainly has data (truncated):

jaspe PS> $data.catalog.book

id           : bk101
author       : Gambardella, Matthew
title        : XML Developer's Guide
genre        : Computer
price        : 44.95
publish_date : 2000-10-01
description  : An in-depth look at creating applications
                     with XML.

id           : bk102
author       : Ralls, Kim
title        : Midnight Rain
genre        : Fantasy
price        : 5.95
publish_date : 2000-12-16
description  : A former architect battles corporate zombies,
                     an evil sorceress, and her own childhood to become queen
                     of the world.
...

I tried this in both Windows Terminal running PowerShell Core as well as pwsh.exe, which I guess uses the trusty conhost. Both produced the same error.

Piping to Out-GridView and Out-GridHTML produces expected output

Update

I just updated PowerShell to 7.0.3 and got the exact same error. I also updated PowerShell on my MacBook to 7.0.3 and got the exact same error using the exact same method. I also ran PowerShell on my Linux system (not WSL) running 7.0.3 and got the same error using the same method.

jasper-zanjani avatar Aug 28 '20 21:08 jasper-zanjani

I can repro. I'll take a look.

tig avatar Sep 28 '20 02:09 tig

Ok, this is beyond my knowledge of PS. What I've found is the cmdlet's ProcessRecord method gets called but InputObject is null.

tig avatar Sep 28 '20 02:09 tig

@tig were your repro steps the same?

TylerLeonhardt avatar Sep 30 '20 16:09 TylerLeonhardt

Yes. I grabbed his XML file and tested as he showed.

tig avatar Sep 30 '20 18:09 tig

@andschwa please prefix title with "OCGV: ".

tig avatar Aug 24 '22 12:08 tig