title: PowerShell: Unable to find type when using PS 5 classes
body: <p>I'm using classes in PS with WinSCP PowerShell Assembly. In one of the methods I'm using various types from WinSCP.</p>
  <p>This works fine as long as I already have the assembly added - however, because of the way PowerShell reads the script when using classes (I assume?), an error is thrown before the assembly could be loaded.</p>
  <p>In fact, even if I put a <code>Write-Host</code> at the top, it will not load.</p>
  <p>Is there any way of forcing something to run before the rest of the file is parsed?</p>
  <pre><code>Transfer() {
      $this.Logger = [Logger]::new()
      try {
  
          Add-Type -Path $this.Paths.WinSCP            
          $ConnectionType = $this.FtpSettings.Protocol.ToString()
          $SessionOptions = New-Object WinSCP.SessionOptions -Property @{
              Protocol = [WinSCP.Protocol]::$ConnectionType
              HostName = $this.FtpSettings.Server
              UserName = $this.FtpSettings.Username
              Password = $this.FtpSettings.Password
          }
  </code></pre>
  <p>Results in an error like this:</p>
  <pre class="lang-none prettyprint-override"><code>Protocol = [WinSCP.Protocol]::$ConnectionType
  Unable to find type [WinSCP.Protocol].
  </code></pre>
  <p>But it doesn't matter where I load the assembly. Even if I put the <code>Add-Type</code> cmdlet on the topmost line with a direct path to <code>WinSCPnet.dll</code>, it won't load - it detects the missing types before running anything, it seems.</p>