title: Unable to load XAML in powershell
body: <p>I have a very basic powershell script that loads a xaml layout. It is throwing this error:</p>
  
  <blockquote>
    <p>Exception calling "Load" with "1" argument(s): <br/>
    "cannot create instance of 'Window' defined in <br/>
    assembly 'PresentationFramework, Version=3.0.0.0, <br/>
    Culture=neutral, PublicKeyToken=31bf3856ad364e35'. <br/>
    The calling thread must be STA, because many UI components require this. " <br/></p>
  </blockquote>
  
  <p>I've gone over the script and xaml files several times, but I'm not seeing where the problem is, and it doesn't help that I don't fully understand what the error I'm getting means either. Any help would be much appreciated. Thank You.</p>
  
  <p>Powershell script:</p>
  
  <pre><code>Add-Type -AssemblyName presentationframework
  $xaml = [xml](Get-Content MainWindow.xaml)
  $reader = New-Object System.Xml.XmlNodeReader $xaml
  $form = [Windows.Markup.XamlReader]::Load($reader)
  $button = $form.FindName('testButton')
  $button.Add_Click({
      $s = $form.FindName('testBox').Text;
      $form.FindName('testLabel').Content = $s;
  })
  $form.ShowDialog()
  </code></pre>
  
  <p>Xaml file:</p>
  
  <pre><code>&lt;Window
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      x:Name="Window"
      Title="MainWindow"
      Width="640" Height="480"&gt;
  
      &lt;Grid x:Name="LayoutRoot"&gt;
          &lt;TextBox x:Name="testBox" HorizontalAlignment="Left"
                   Margin="26.782,48.626,0,0" TextWrapping="Wrap"
                   Text="New label text" VerticalAlignment="Top" Width="130.22"/&gt;
          &lt;Label x:Name="testLabel" Content="User Search" HorizontalAlignment="Left"
                   Margin="20.666,22.666,0,0" VerticalAlignment="Top"/&gt;
          &lt;Button x:Name="testButton" Content="Change It!" HorizontalAlignment="Left"
                   Margin="26.782,85,0,0" VerticalAlignment="Top" Width="75"/&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>