19 Replies
what gives an error and can you screenshot it?
You can't use a variable as a type
yes, use reflection to get the correct generic instantiation of the method
I don't need a method from the type
you need the correct generic method, which you can't get with a variable using that syntax
I need to invoke the powershell method with a type that I will only be able to know by name
yes, i know what you're trying to do
you can't do it without more reflection
you need to get the method info for the open generic
powershell.Invoke
method then make the generic method using the type variable so you can call it
something roughly like
Okay, so that is similar to what I had seen, it just looked like it wasn't what I needed
[Error: Ambiguous match found.] {
name: 'System.Reflection.AmbiguousMatchException'
}
Close, but should be able to get there
you'll have to provide enough information to
GetMethod
to make it not ambiguous
i don't know what type powershell
is but i'd guess there are multiple overloads of Invoke
Yeah, there's 8
I call it with no params
powershell.Invoke();
But calling
fooMethod.Invoke()
with no params throws an erroryou have to pass it the
powershell
instance since it's not a static methodfooMethod.Invoke(powershell, new object[] { })
not sure you need to pass it an empty array, i haven't had to do reflection like this in a bit
.GetMethod("Invoke", BindingFlags.Public | BindingFlags.Instance, []);
should find the parameterless overload you want if you didn't get that yetI tried
null
too
Ah sorry, this was Frameworkah, substitute
[]
for an empty array then
no cool syntax allowed in frameworkYeah, I hate this vendor
maybe the api is different :PepeHmmm:
ultimately you want to give it the empty type array, so whatever overload lets you do that with the least amount of extra stuff
:SCtwocats: