title: Powershell unable to find type [System.Windows.Forms.KeyEventHandler]
body: <p>This might be a pretty simple question but I'm totally lost and searching for an answer hasn't been helpful.</p>
  
  <p>I've got some powershell code to display a simple GUI with TextBoxes.  Some of the textboxes allows the user to press Enter to run Button_Click code.  When I try running the PS1 script, I get errors saying the following:</p>
  
  <pre><code>Unable to find type [System.Windows.Forms.KeyEventHandler].
  Make sure that the assembly that contains this type is loaded.At C:\Scripts\GUI-Testing.ps1:161 char:1
  
  $TestVar=[System.Windows.Forms.KeyEventHandler]
  CategoryInfo          : InvalidOperation: (System.Windows.Forms.KeyEventHandler:TypeName)
  FullyQualifiedErrorId : TypeNotFound
  </code></pre>
  
  <p>The strange part, if I close the GUI then re-run the script, I don't get the <code>Unable to find type</code> error and pressing Enter works as desired.</p>
  
  <p>Thinking I had an answer, I tried using <code>[void][reflection.assembly]::Load('System.Windows.Forms.KeyEventHandler')</code> which give this error <code>Exception calling "Load" with "1" argument(s): "Could not load file or assembly 'System.Windows.Forms.KeyEventHandler' or one of its dependencies. [FileNotFoundException]</code></p>