Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@powercode

Description

@powercode
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    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.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Languageparser, language semanticsparser, language semantics

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.