Exception when loading: [System.Windows.Markup.XamlReader]::Load($XmlNodeReader)
See original GitHub issueVSCode Version: 1.41.1 with PowerShell Extension. No Other Extensions are installed
OS Version: Windows 10 - Ver. 1909
Steps to Reproduce:
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAML = $inputXML
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
$Form=[System.Windows.Markup.XamlReader]::Load($reader)
When running Powershell Core 7 RC2 in VSC: This Exception is thrown when loading: [System.Windows.Markup.XamlReader]::Load($reader): “Exception calling “Load” with “1” argument(s): ‘The invocation of the constructor on type ‘System.Windows.Window’ that matches the specified binding constraints threw an exception.’”
It is the same issue regardless how I run the Code - by the RUN button or from the command line in the terminal window by calling the script file
When running the exact the same script file from command line in Powershell Core 7 RC2 without VSC involved, then no Exception is thrown and the script works perfect.
There is no issue in VSC when running the script in Powershell 5.1.
Powershell Extension is the only one installed. When i disable PowerShell Extension I am able to run the script from command line in the terminal window.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7

Top Related StackOverflow Question
The Preview version of the extension has the same version number 2020.1.0, so previous I did not think it was worth trying to use the preview version, but by your request I tried and my problems was solve. Thanks for your assistance 😃
Wait, writing a response here I just had an idea. I’m suspecting that the issue you’re having is something that’s only present in the stable extension. If you can, try
powershell-previewand see if the issue is resolved. That will become stable this month.Of course! The PowerShell extension gets almost all of its functionality from a PowerShell process behind the scenes. But all of the interaction that looks like PowerShell in the extension is actually running in quite a different way due to the constraints of PowerShell’s architecture.
Completions in PowerShell come from the current runspace and are entirely contextual, so most of the complexity in the extension is devoted to an architecture where we:
To do this, we have to carefully shuttle things to and from the pipeline thread. This involves careful management of the runtime state of the process, including the runspaces. So the PowerShell that you’re running in the Integrated Console, in order to be integrated, is quietly running some other threads to give you PowerShell extension features.
BUT, as I realised above, if you’re running the stable extension you’re probably missing out on a lot of small changes we’ve made to the extension to basically get out of the way of scripts.