Skip to content

Built-in format data contains dormant duplicates #11307

@mklement0

Description

@mklement0

If you use Get-FormatData -PowerShellVersion 5.1 to enumerate all built-in format-data definitions, duplicates surface.

While different format-data definitions may cover different views for a given type (and format-data definitions may cover multiple types), there are truly competing definitions, only one of which can be effective, as the repro steps demonstrate for type System.Management.Automation.AliasInfo.

All built-in format-data definitions should be examined, and the ineffective duplicates should be omitted. Update: See the bottom for a list of all duplicates.

Steps to reproduce

Get-FormatData | ? TypeNames -Contains System.Management.Automation.AliasInfo | 
  % FormatViewDefinition | 
    ? Control -is System.Management.Automation.TableControl

Expected behavior

Only one table-view control definition should be printed for the given type.

Actual behavior

Two - competing - definitions print:

Name        Control
----        -------
CommandInfo System.Management.Automation.TableControl
AliasInfo   System.Management.Automation.TableControl

Only the former is in effect (Name column prints an alias' .DisplayName property).

The latter (there's only a DisplayName property) is never used.

Environment data

PowerShell Core 7.0.0-preview.6

Query to find all duplicates:

Get-FormatData | ForEach-Object {
    $fd = $_
    $_.formatviewdefinition | Select-Object @{n='TypeName'; e = { $fd.TypeNames } }, @{n='ControlType'; e={ $_.Control.GetType().Name } }
} 
| Group-Object -Property TypeName, ControlType | Where-Object Count -gt 1 
| Format-Table -AutoSize

In a pristine session, this yields:

Count Name                                                                        Group
----- ----                                                                        -----
    2 Microsoft.PowerShell.Commands.X509StoreLocation, ListControl                {@{TypeName=Microsoft.PowerShell.Commands.X509StoreLocation; ControlType=ListControl}, @{TypeNam…
    2 System.Management.Automation.AliasInfo, TableControl                        {@{TypeName=System.Management.Automation.AliasInfo; ControlType=TableControl}, @{TypeName=System…
    2 System.Management.Automation.ApplicationInfo, TableControl                  {@{TypeName=System.Management.Automation.ApplicationInfo; ControlType=TableControl}, @{TypeName=…
    2 System.Management.Automation.ExternalScriptInfo, TableControl               {@{TypeName=System.Management.Automation.ExternalScriptInfo; ControlType=TableControl}, @{TypeNa…
    2 System.Management.Automation.FilterInfo, TableControl                       {@{TypeName=System.Management.Automation.FilterInfo; ControlType=TableControl}, @{TypeName=Syste…
    2 System.Management.Automation.FunctionInfo, TableControl                     {@{TypeName=System.Management.Automation.FunctionInfo; ControlType=TableControl}, @{TypeName=Sys…
    2 System.Management.Automation.ScriptInfo, TableControl                       {@{TypeName=System.Management.Automation.ScriptInfo; ControlType=TableControl}, @{TypeName=Syste…
    2 System.Security.Cryptography.X509Certificates.X509Certificate2, ListControl {@{TypeName=System.Security.Cryptography.X509Certificates.X509Certificate2; ControlType=ListCont…
    2 System.Security.Cryptography.X509Certificates.X509Store, ListControl        {@{TypeName=System.Security.Cryptography.X509Certificates.X509Store; ControlType=ListControl}, @…

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions