Unable to load XAML in powershell Unable to load XAML in powershell powershell powershell

Unable to load XAML in powershell


This error is what I call the "because I said so error", and it means exactly what it says.

You can't load XAML in Powershell.exe because it's STA. And "many" components require this. My many, I mean WPF.

Luckily, every PowerShell host supports STA

  • powershell.exe -sta (turns on STA mode)
  • Powershell Integrated Scripting Environment (STA by default)
  • PowerGUI (STA by default)
  • PowerShellPlus (hold shift in startup to turn on STA)
  • PrimalScript (it's in a checkbox along the top bar)
  • PowerSE / PowerWF (STA coming soon)

There are much easier ways to write UI in PowerShell though. You should check out showui.codeplex.com.

Hope this helps,


@BrandonRisell, check out ShowUI a PowerShell module to help build WPF user interfaces in script.

ShowUI makes the complicated world of WPF easy to use in PowerShell. You can use ShowUI to write simple WPF gadgets, quick front ends for your scripts, components, and full applications.


It means that your main() must be annotated with [STAThread] and I'm not sure it's possible in powershell.
For more info about STA vs. MTA see here.