title: Call MessageBox within Powershell Class
body: <p>All</p>
  <p>I'm new to powershell and I'm trying to write a class with pop out the message box while something wrong. It looks like when in the class the powershell cannot find the type of [System.Windows.Forms.MessageBox], meanwhile, the parameter type also cannot recognize the [System.Windows.Forms.xxxx]. How can I solve this issue? Here is some sample code below.And I also got the error messages in vscode as listed.Any help from you are appreciated!</p>
  <p><strong>Sample Code</strong></p>
  <pre><code>Add-Type -AssemblyName System.Windows.Forms
  Add-Type -AssemblyName System.Drawing
  Add-Type -AssemblyName PresentationFramework
  Add-Type -AssemblyName PresentationCore,PresentationFramework
  Class Test
  {
      [System.Windows.Forms.Form]$form
  
      Test()
      {
          [System.Windows.Forms.MessageBox]::Show(&quot;Class Created!&quot;,&quot;Info&quot;,&quot;OK&quot;,&quot;Info&quot;)|Out-Null
      }
  }
  [Test]::new()
  </code></pre>
  <p><strong>ERROR MESSAGES</strong></p>
  <pre><code>[Running] powershell -ExecutionPolicy ByPass -File &quot;c:\PowerShell\tempCodeRunnerFile.ps1&quot;
  At C:\PowerShell\tempCodeRunnerFile.ps1:7 char:6
  +     [System.Windows.Forms.Form]$form
  +      ~~~~~~~~~~~~~~~~~~~~~~~~~
  Unable to find type [System.Windows.Forms.Form].
  At C:\PowerShell\tempCodeRunnerFile.ps1:11 char:10
  +         [System.Windows.Forms.MessageBox]::Show(&quot;Class Created!&quot;,&quot;Inf ...
  +          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Unable to find type [System.Windows.Forms.MessageBox].
      + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
      + FullyQualifiedErrorId : TypeNotFound
   
  
  [Done] exited with code=1 in 0.409 seconds
  </code></pre>
  <p><strong>PS-VERSION-TABLE</strong></p>
  <pre><code>PS C:\PowerShell&gt; $PSversiontable
  
  Name                           Value
  ----                           -----
  PSVersion                      5.1.19041.1320
  PSEdition                      Desktop
  PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
  BuildVersion                   10.0.19041.1320
  CLRVersion                     4.0.30319.42000
  WSManStackVersion              3.0
  PSRemotingProtocolVersion      2.3
  SerializationVersion           1.1.0.1
  </code></pre>