Skip to content

CodeMethod invoke fails with dot syntax but works with Foreach-Object -MemberName #4826

@powercode

Description

@powercode

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Languageparser, language semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions