Steps to reproduce
using namespace System.Management.Automation
class Y {
[int ] $Id
}
class X {
static [void ] OpenUri([psobject ] $obj ) {
$id = $obj.Id
start-process " http://baseuri/$id "
}
static [void ] UpdateTypeData(){
$td = [Runspaces.Typedata ]::new([Y ])
$td.Members.Add (" OpenUri" ,
[Runspaces.CodeMethodData ]::new(" OpenUri" , [X ]::GetMethodInfo([X ], " OpenUri" )));
Update-TypeData - TypeData $td - Force
}
hidden static [Reflection.MethodInfo ] GetMethodInfo([Type ] $type , [string ] $method ) {
return $type.GetMethod ($method , [Reflection.BindingFlags ]::Static -bor [Reflection.BindingFlags ]::Public -bor [Reflection.BindingFlags ]::IgnoreCase);
}
}
[X ]::UpdateTypeData()
$y = [Y ]::new()
# works
$y | % OpenUri
# fails with No coercion operator is defined between types 'System.Void' and 'System.Object'.
$y.OpenUri ()
Expected behavior
Same behavior invoking method with dot syntax as when invoked via Foreach-Object -MemberName
Actual behavior
fails with
No coercion operator is defined between types 'System.Void' and 'System.Object'.
At line:1 char:1
+ $y.OpenUri()
PS C:\Program Files\PowerShell\6.0.0-beta.6> $y | gm
TypeName: Y
Name MemberType Definition
---- ---------- ----------
OpenUri CodeMethod static void OpenUri(psobject obj)
Environment data
All versions (beta 6 and win 5.1)
Reactions are currently unavailable
Steps to reproduce
Expected behavior
Same behavior invoking method with dot syntax as when invoked via
Foreach-Object -MemberNameActual behavior
fails with
Environment data
All versions (beta 6 and win 5.1)