Skip to content

EntrySelectedBy in CustomControls do not pass on the current object to expressions #7847

Description

Steps to reproduce

$text = '<?xml version="1.0" encoding="UTF-8" ?>
<Configuration>
    <Controls>
        <Control>
            <Name>MyTestControl</Name>
            <CustomControl>
                <CustomEntries>
                    <CustomEntry>
                        <EntrySelectedBy>
                            <SelectionCondition>
                                <TypeName>MyTestObject</TypeName>
                                <PropertyName>MyProperty</PropertyName>
                            </SelectionCondition>
                        </EntrySelectedBy>
                        <CustomItem>
                            <Text>Selection successful</Text>
                        </CustomItem>
                    </CustomEntry>
                    <CustomEntry>
                        <CustomItem>
                            <Text>Default was picked</Text>
                        </CustomItem>
                    </CustomEntry>
                </CustomEntries>
            </CustomControl>
        </Control>
    </Controls>
    <ViewDefinitions>
        <View>
            <Name>DefaultView</Name>
            <ViewSelectedBy>
                <TypeName>MyTestObject</TypeName>
            </ViewSelectedBy>
            <GroupBy>
                <PropertyName>MyProperty</PropertyName>
                <CustomControlName>MyTestControl</CustomControlName>
            </GroupBy>
            <TableControl>
                <TableHeaders>
                    <TableColumnHeader />
                </TableHeaders>
                <TableRowEntries>
                    <TableRowEntry>
                        <TableColumnItems>
                            <TableColumnItem>
                                <PropertyName>Name</PropertyName>
                            </TableColumnItem>
                        </TableColumnItems>
                    </TableRowEntry>
                </TableRowEntries>
            </TableControl>
        </View>
    </ViewDefinitions>
</Configuration>'

Set-Content $env:TEMP\test.format.ps1xml -Value $text -Force
Update-FormatData -AppendPath $env:TEMP\test.format.ps1xml

[PSCustomObject]@{
    PSTypeName = 'MyTestObject'
    MyProperty = 'testing'
    Name = 'testing'
}

Expected behavior

Selection successful

Name
----
testing

Actual behavior

format-default : Object reference not set to an instance of an object.
    + CategoryInfo          : NotSpecified: (:) [format-default], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.FormatDefaultCommand

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.1.0
PSEdition                      Core
GitCommitId                    6.1.0
OS                             Microsoft Windows 10.0.16299
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Additional Information

This works as expected after changing this line to this:

if (match.PerfectMatch(new TypeMatchItem(x, x.appliesTo, so)))

Activity

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-Enhancementthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.WG-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