title: TypeConverter (registration) throws NullRefException in PowerShell
body: <p>I have a PowerShell class, which I want to automatically be convertable from <code>string</code>.</p>
  
  <p>So I defined a TypeConverter like this:</p>
  
  <pre><code>    class StringToAcmeStateConverter : System.Management.Automation.PSTypeConverter {
      [bool] CanConvertFrom([object] $object, [Type] $destinationType) {
          if($object -is [string]) {
              return Test-Path ([string]$object);
          }
  
          return $false;
      }
  
      [bool] CanConvertTo([object] $object, [Type] $destinationType) {
          return $false
      }
  
      [object] ConvertFrom([object] $sourceValue, [Type] $destinationType,
          [IFormatProvider] $formatProvider, [bool] $ignoreCase)
      {
          if($null -eq $sourceValue) { return $null; }
  
          if(-not $this.CanConvertFrom($sourceValue, $destinationType)) {
              throw [System.InvalidCastException]::new();
          }
  
          $paths = [AcmeStatePaths]::new($sourceValue);
          return [AcmeDiskPersistedState]::new($paths, $false, $true);
      }
  
      [object] ConvertTo([object] $sourceValue, [Type] $destinationType,
          [IFormatProvider] $formatProvider, [bool] $ignoreCase)
      {
          throw [System.NotImplementedException]::new();
      }
  }
  
  [System.ComponentModel.TypeConverter([StringToAcmeStateConverter])]
  &lt;# abstract #&gt; class AcmeState {
      AcmeState() {
          if ($this.GetType() -eq [AcmeState]) {
              throw [System.InvalidOperationException]::new("This is intended to be abstract - inherit To it.");
          }
      }
  
      &lt;# omitted #&gt;
  }
  </code></pre>
  
  <p>(Full code listing here: <a href="https://raw.githubusercontent.com/PKISharp/ACMESharpCore-PowerShell/deep-state/ACME-PS/internal/classes/AcmeState.ps1" rel="nofollow noreferrer">https://raw.githubusercontent.com/PKISharp/ACMESharpCore-PowerShell/deep-state/ACME-PS/internal/classes/AcmeState.ps1</a>)</p>
  
  <p>But PowerShell now throws a NullRefException from inside the pipeline.
  How would I make PS use the Converter correctly.</p>
  
  <p><strong>Update</strong></p>
  
  <p>Since this question did not contain enough information for a full repro, I created a gist containing the current (failing) code of the module: gist.github.com/glatzert/ba32f291b9155e6d19c29fbe9594a7c5</p>