Skip to content

Group-Object fails with a NullReferenceException on empty noteproperty  #3300

Closed

Description

Repro:

PS C:\Users\slee> $x = 1 | Select-Object -Property @{Name = 'X'; Expression = {}}
PS C:\Users\slee> $x | Group-Object X

Expected

Count Name                      Group
----- ----                      -----
    1                           {@{X=}}

Actual

Group-Object : Object reference not set to an instance of an object.
At line:1 char:6
+ $x | Group-Object X
+      ~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Group-Object], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.GroupObjectCommand

Workaround

PS C:\Users\slee> $x = 1 | Select-Object -Property @{Name = 'X'; Expression = {$null}}
PS C:\Users\slee> $x | Group-Object X

Count Name                      Group
----- ----                      -----
    1                           {@{X=}}

TFS:10939589

PSVersionTable

PS C:\Users\slee> $psversiontable

Name                           Value
----                           -----
GitCommitId                    v6.0.0-alpha.17
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
CLRVersion
SerializationVersion           1.1.0.1
PSEdition                      Core
BuildVersion                   3.0.0.0
PSVersion                      6.0.0-alpha
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3

Activity

  1. added
    WG-Engine
    on Mar 10, 2017
  2. added
    Issue-Bug
    on Oct 8, 2017
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-BugResolution-FixedWG-Engine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions