Cannot call overloaded methods of .NET API in PowerShell

428 Views Asked by At

I have a 3rd party API that I want to use in a PowerShell script. I can instantiate the objects and access properties and non-overloaded methods, but every call to an overloaded method fails with Cannot find an overload for "<method>" and the argument count: "<count>".

The API works fine when called from C#.

Example (here $doc0 contains an instance of an object from the API and Value is the method I want to call):

PS C:\> $doc0.Value.OverloadDefinitions
System.Object IPSFNetDataItem.Value(int fieldIndex)
System.Object IPSFNetDataItem.Value(string field)

PS C:\> $doc0.FieldName(0) #Non-overloaded methods are ok.
ID

PS C:\> $doc0.Value([int]0) #overloaded methods fail
Cannot find an overload for "value" and the argument count: "1".
At line:1 char:1
+ $doc0.Value([int]0) #overloaded methods fail
+ ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest


PS C:\> $doc0.Value([string]"why?") #overloaded methods fail
Cannot find an overload for "value" and the argument count: "1".
At line:1 char:1
+ $doc0.Value([string]"why?") #overloaded methods fail
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

I have looked at other similar questions (e.g. here and here) but these solutions do not work in this case - there is surely no room for ambiguity in this very simple case and as the output from OverloadDefinitions shows, I am not trying to do anything that is not supported but the API.

I assume that PowerShell isn't usually this bad at resolving method calls; any ideas why this might be failing?

0

There are 0 best solutions below