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

Show-ObjectTree does not enumerate object data from PSObject converted from JSON via ConvertFrom-JSON. #242

Open
3 tasks done
RokeJulianLockhart opened this issue Mar 16, 2024 · 2 comments · May be fixed by #243
Open
3 tasks done

Comments

@RokeJulianLockhart
Copy link

RokeJulianLockhart commented Mar 16, 2024

  1. Prerequisites

  2. Steps to reproduce

    As https://github.com/orgs/PowerShell/discussions/21343#discussioncomment-8810840 states, it doesn't appear to parse the object:

    1. Initialize a variable as JSON

      $Values = @'
      {
      	"Candidate":
      	{
      		"Name": {
      			"3rd": "Surname",
      			"1st": "Forename",
      			"2nd": "Middle name"
      		},
      		"Date of Birth": "+1582-10-15",
      		"E-mail Address": "mailTo:address@domain.TLD",
      		"Mobile Telephone Number": "tel:+00-0000-000000",
      		"Blood Group": "" // Unknown
      	},
      	"Mother":
      	{
      		"Name": {
      			"3rd": "Surname",
      			"1st": "Forename",
      			"2nd": "Middle name"
      		},
      		"Date of Birth": "+1582-10-15",
      		"E-mail Address": "mailTo:address@domain.TLD",
      		"Mobile Telephone Number": "tel:+00-0000-000000",
      	},
      	"Father":
      	{
      		"Name": {
      			"3rd": "Surname",
      			"1st": "Forename",
      			"2nd": "Middle name"
      		},
      		"Date of Birth": "+1582-10-15",
      		"E-mail Address": "mailTo:address@domain.TLD",
      		"Mobile Telephone Number": "tel:+00-0000-000000",
      	},
      }
      '@
    2. Pass the value via a pipe to Show-ObjectTree.

    Expected behavior

    It should display as Get-Process | Show-ObjectTree does:

    Screenshot_20240316_174327

  3. Actual behavior

    1. Visuals

        1. $Values | Show-ObjectTree
        2. Screenshot_20240316_104948

        1. $Values | ConvertFrom-JSON | Show-ObjectTree
        2. Screenshot_20240316_105413

        3. When that expansion indicator is invoked, it disappears:

          Screenshot_20240316_105424

  4. Error details

    Get-Error

    returns $Null.

  5. Environment data

    {
      "PSVersion": {
        "Major": 7,
        "Minor": 4,
        "Patch": 1,
        "PreReleaseLabel": null,
        "BuildLabel": null
      },
      "OS": "cpe:/o:opensuse:tumbleweed:20240314",
      "PSRemotingProtocolVersion": {
        "Major": 2,
        "Minor": 3,
        "Build": -1,
        "Revision": -1,
        "MajorRevision": -1,
        "MinorRevision": -1
      },
      "PSEdition": "Core",
      "GitCommitId": "7.4.1",
      "Platform": "Unix",
      "PSCompatibleVersions": [
        {
          "Major": 1,
          "Minor": 0,
          "Build": -1,
          "Revision": -1,
          "MajorRevision": -1,
          "MinorRevision": -1
        },
        {
          "Major": 2,
          "Minor": 0,
          "Build": -1,
          "Revision": -1,
          "MajorRevision": -1,
          "MinorRevision": -1
        },
        {
          "Major": 3,
          "Minor": 0,
          "Build": -1,
          "Revision": -1,
          "MajorRevision": -1,
          "MinorRevision": -1
        },
        {
          "Major": 4,
          "Minor": 0,
          "Build": -1,
          "Revision": -1,
          "MajorRevision": -1,
          "MinorRevision": -1
        },
        {
          "Major": 5,
          "Minor": 0,
          "Build": -1,
          "Revision": -1,
          "MajorRevision": -1,
          "MinorRevision": -1
        },
        {
          "Major": 5,
          "Minor": 1,
          "Build": -1,
          "Revision": -1,
          "MajorRevision": -1,
          "MinorRevision": -1
        },
        {
          "Major": 6,
          "Minor": 0,
          "Build": -1,
          "Revision": -1,
          "MajorRevision": -1,
          "MinorRevision": -1
        },
        {
          "Major": 7,
          "Minor": 0,
          "Build": -1,
          "Revision": -1,
          "MajorRevision": -1,
          "MinorRevision": -1
        }
      ],
      "WSManStackVersion": {
        "Major": 3,
        "Minor": 0,
        "Build": -1,
        "Revision": -1,
        "MajorRevision": -1,
        "MinorRevision": -1
      },
      "SerializationVersion": {
        "Major": 1,
        "Minor": 1,
        "Build": 0,
        "Revision": 1,
        "MajorRevision": 0,
        "MinorRevision": 1
      }
    }
  6. Version

    1. PowerShell

      snap install $(what-snap JSNnoJl3EqkMuWoy5Dgq8PMqZ0uNcpie | awk '{print $2}') --classic --channel=latest/stable --revision 264
    2. Microsoft.PowerShell.ConsoleGuiTools

      1. Get-InstalledModule -Name 'Microsoft.PowerShell.ConsoleGuiTools' | Select-Object -ExpandProperty 'Version'
      2. https://github.com/PowerShell/GraphicalTools/releases/tag/v0.7.6.0

@tznind
Copy link
Contributor

tznind commented Mar 17, 2024

The input object produced by $Values | ConvertFrom-JSON | Show-ObjectTree is a single System.Management.Automation.PSCustomObject

I am not familiar with this class and cannot seem to find many c# examples of how to work dynamically with the type. However it should be possible to update GetChildren and AspectGetter to behave better than at the moment (blank string no children).

I have started a Redit post to see if anyone knows how to work with this class in c# 🤞 but any insight here would be appreciated too.

These extension methods (see below) seem to behave badly at runtime too. Also I think they are a read herring. They are most likely just generic extension methods.

PS D:\Repos\GraphicalTools> $Values | ConvertFrom-JSON | Show-ObjectTree
Show-ObjectTree: Could not load file or assembly 'Namotion.Reflection, Version=2.0.10.0, Culture=neutral, PublicKeyToken=c2f9c3bdfae56102'. The system cannot find the file specified.

image

@tznind tznind linked a pull request Mar 17, 2024 that will close this issue
@tznind
Copy link
Contributor

tznind commented Mar 17, 2024

I have made some progess and opened a WIP PR.

If done correctly this should also mean that other use cases for custom objects will work better. And the refactoring work in the PR will also make it more flexible to future changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants