0

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?

aucuparia
  • 2,021
  • 20
  • 27
  • Does the issue stop if you remove the explicit type? e.g. `$doc0.Value("why?")` I'm not sure why your doing that but if you must you can wrap them in a subexpression. `$doc0.Value($([string]"why?"))` and it should work. – Persistent13 Sep 06 '17 at 21:06
  • Makes no difference either way - still the same issue. The explicit type was just to try and see if there was anything funny going on with type conversion. – aucuparia Sep 07 '17 at 09:11
  • Any chance you can share what 3rd party API you are using? I'd like to see if it is possible to get a copy and try tinkering with it. – Persistent13 Sep 07 '17 at 15:06
  • It's PS Financials (PSFNetObjects.dll) v6.0.0.925. I doubt if you'll be able to get one as AFAIK they don't licence or release the API separately from the rest of the software. – aucuparia Sep 07 '17 at 16:56

0 Answers0