title: How can I call an overloaded .NET function which uses a C# out argument from Powershell?
body: <p>I know that Powershell can call .NET code, which might look like this</p>
  
  <pre><code>PS&gt; [Reflection.Assembly]::LoadFile(($ScriptDir + ".\SharpSvn-x64\SharpSvn.dll"))
  PS&gt; $SvnClient = New-Object SharpSvn.SvnClient
  </code></pre>
  
  <p>And I know that where C# has <code>out</code> arguments, Powershell has <code>[ref]</code> arguments, which might look like this: </p>
  
  <pre><code>PS&gt; $info = $null
  PS&gt; $SvnClient.GetInfo($repo.local, ([ref]$info))
  
  True
  
  PS&gt; $info
  
  (...long output snipped...)
  NodeKind           : Directory
  Revision           : 16298
  Uri                : http://server/path/to/remoterepo
  FullPath           : C:\path\to\localrepo
  (...long output snipped...)
  </code></pre>
  
  <p>And I know that in C# you can overload functions, like the SharpSvn library does for its <a href="http://docs.sharpsvn.net/current/html/Overload_SharpSvn_SvnClient_Update.htm" rel="noreferrer">SvnClient.Update() method</a>:</p>
  
  <ol>
  <li><code>Update(ICollection(String))</code> - Recursively updates the specified paths to the latest (HEAD) revision</li>
  <li><code>Update(String)</code> - Recursively updates the specified path to the latest (HEAD) revision</li>
  <li><code>Update(ICollection(String), SvnUpdateArgs)</code> - Updates the specified paths to the specified revision</li>
  <li><code>Update(ICollection(String), SvnUpdateResult)</code> - Recursively updates the specified paths to the latest (HEAD) revision</li>
  <li><code>Update(String, SvnUpdateArgs)</code> - Recursively updates the specified path</li>
  <li><code>Update(String, SvnUpdateResult)</code> - Recursively updates the specified path to the latest (HEAD) revision</li>
  <li><code>Update(ICollection(String), SvnUpdateArgs, SvnUpdateResult)</code> - Updates the specified paths to the specified revision</li>
  <li><code>Update(String, SvnUpdateArgs, SvnUpdateResult)</code> - Recursively updates the specified path to the latest (HEAD) revision</li>
  </ol>
  
  <p>But, what if we want to put all of this together? If, say, I want to call the 6th version of <code>Update()</code>, the one that takes a String and an SvnUpdateResult, where the SvnUpdateResult is a C# out object? My first instinct was to try something like this: </p>
  
  <pre><code>PS&gt; $repopath = "C:\path\to\localrepo"
  PS&gt; $update = $null
  PS&gt; $svnclient.update($repopath, [ref]$update)
  
  Multiple ambiguous overloads found for "Update" and the argument count: "2".
  At line:1 char:18
  + $svnclient.update &lt;&lt;&lt;&lt; ($repopath, [ref]$update)
      + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
      + FullyQualifiedErrorId : MethodCountCouldNotFindBest
  </code></pre>
  
  <p>OK, maybe I have to cast the arguments? </p>
  
  <pre><code>PS&gt; $svnclient.update([string]$repopath, [ref][SharpSvn.SvnUpdateResult]$update)
  
  Multiple ambiguous overloads found for "Update" and the argument count: "2".
  At line:1 char:18
  + $svnclient.update &lt;&lt;&lt;&lt; ([string]$repopath, [ref][SharpSvn.SvnUpdateResult]$update)
      + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
      + FullyQualifiedErrorId : MethodCountCouldNotFindBest
  </code></pre>
  
  <p>But that doesn't seem to work either. Other things I've tried:</p>
  
  <ul>
  <li>casting <code>$update</code> as <code>[SharpSvn.SvnUpdateResult][ref]</code> - that is, reversing the order that I cast it. That results in an error which states: "[ref] can only be the final type in type conversion sequence."</li>
  <li>Casting <code>$update</code> to <code>SharpSvn.SvnUpdateResult</code> before using it: <code>$update = [SharpSvn.SvnUpdateResult]$null</code>. This results in the same "Multiple ambiguous overloads" error I ran into above</li>
  <li>Casting <code>$update</code> to <code>ref</code> before using it: <code>$update = [ref]$null</code>. This results in an error: 'Cannot convert the "System.Management.Automation.PSReference" value of type "System.Management.Automation.PSReference" to type "SharpSvn.SvnUpdateResult".'</li>
  </ul>
  
  <p>It seems like casting it twice is the problem - the final cast just overrides the first cast, they don't complement each other. Is this what's happening? Is there a way to cast something twice? Is there another way around this problem? </p>
  
  <p>Thanks in advance for any help. </p>