Skip to content

Need implicit conversion for private static method call args #3

@vors

Description

@vors
Add-Type @'
namespace foo5
{
    public class bar
    {
        private static int fooL(System.Reflection.MethodInfo mi) { return 1; }
    }
}
'@

$f = [foo5.bar] | peek
$mi = [System.Collections.ObjectModel.Collection[PSObject]].GetMethods() | ? {$_.Name -eq 'Add'}
$f.fooL($mi)

Expected output:

1

Actual error

Exception calling "fooL" with "1" argument(s): "Exception calling "Invoke" with "5" argument(s): "Object of type 
'System.Management.Automation.PSObject' cannot be converted to type 'System.Reflection.MethodInfo'.""
At line:13 char:1
+ $f.fooL($mi)
+ ~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ScriptMethodRuntimeException

Workaround: cast arg explicitly

$f.fooL([System.Reflection.MethodInfo]$mi)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions