Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need implicit conversion for private static method call args #3

Open
vors opened this issue Oct 23, 2015 · 0 comments
Open

Need implicit conversion for private static method call args #3

vors opened this issue Oct 23, 2015 · 0 comments

Comments

@vors
Copy link
Contributor

vors commented Oct 23, 2015

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant