-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.The issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime
Description
This repro’s on 5.1 and 6. The problem is that if I have a DynamicObject that has a dynamic property “Foo”, things like $obj.Foo work, but Select-Object -ExpandProperty Foo do not.
Steps to reproduce
Add-Type @"
using System;
using System.Collections.Generic;
using System.Dynamic;
public class MyDynamicObject : DynamicObject
{
public override IEnumerable<string> GetDynamicMemberNames()
{
return new string[] { "Foo" };
}
public override bool TryGetMember( GetMemberBinder binder, out object result )
{
result = null;
bool succeeded = false;
if( binder.Name == "Foo" )
{
result = 123;
succeeded = true;
}
return succeeded;
}
}
"@
$myObj = [MyDynamicObject]::new()
$myObj.Foo # <-- works
$myObj | %{ $_.Foo } # <-- works
$myObj | Select-Object -ExpandProperty Foo # <-- DOES NOT WORKExpected behavior
The last three lines should all work (yield 123).
Actual behavior
The Select-Object statement throws. ("Select-Object : Property "Foo" cannot be found.")
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 6.1.0-preview.1
PSEdition Core
GitCommitId v6.1.0-preview.1
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.0Metadata
Metadata
Assignees
Labels
Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.The issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime