How can I call an overloaded .NET function which uses a C# out argument from Powershell? How can I call an overloaded .NET function which uses a C# out argument from Powershell? powershell powershell

How can I call an overloaded .NET function which uses a C# out argument from Powershell?


This might not be an ideal solution but you could use Add-Type and make a more PowerShell friendly type that wraps the Update method.

Add-Type -TypeDefinition "public class SvnClientEx{   public static SvnUpdateResult Update(SvnClient client, string path)   {       SvnUpdateResult result;        client.Update(path, out result);       return result;    } }"$result = [SvnClient]::Update($svnClient, $repopath)


This does seem to be quite hard to get right.

What version of PowerShell is this?Are SvnUpdateArgs and SvnUpdateResult related (i.e. one class derives from the other)? I shall assume not.

Based on a similar scenario I constructed, with the current version (4.0) of PowerShell, this works, I think:

PS> $repopath = "C:\path\to\localrepo"PS> [SharpSvn.SvnUpdateResult]$update = $nullPS> $svnclient.Update([string]$repopath, [ref]$update)

However, I could only get this to work with one of the overloads!? Not sure if it is by coincidence, but this was the overload which was listed first when I said $svnclient.Update to see the overload definitions.

In my version of PowerShell, if I give the second argument as [ref][SharpSvn.SvnUpdateResult]$update, the overload seems to be resolved correctly, the method runs without error, but the object assigned to the "out" parameter seems to be lost.

Even if $repopath is declared type-safely as [string]$repopath = "C:\path\to\localrepo", it seems that we still have to say [string]$repopath again when we pass it (by value).


There seems to be an issue in PowerShell when there is a Method that you call with an out parameter of a class and another overload with a similar signature (the class can be any class in this signature.)

I created a simple repro for this issue and filed an issue for PowerShell.