question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception when loading: [System.Windows.Markup.XamlReader]::Load($XmlNodeReader)

See original GitHub issue
VSCode 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:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
HenryHermancommented, Feb 4, 2020

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 😃

0reactions
rjmholtcommented, Feb 4, 2020

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-preview and see if the issue is resolved. That will become stable this month.

Before I continue could you please explain to me, why the script works perfect in PowerShell 7, when I disable the PowerShell Extension in VSC?

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:

  • Use the PowerShell installed on your machine (rather than forcing you to use a particular PowerShell version)
  • Load ourselves into it
  • Take over the pipeline thread
  • Present a prompt over the top of it
  • But also use it to run completions, debugging, code analysis, reference tracking, etc.

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error Windows.Markup.XamlReader Load
I'm trying to run default code after adding WPF window in VisualStudio 2019. Microsoft Visual Studio Community 2019. Version 16.4.2 script:
Read more >
Error when running XAML script with powershell - MSDN
Xml.XmlNodeReader $Form) $Win=[Windows.Markup.XamlReader]::Load( $NR ) $Win.ShowDialog(). Here is the error: Exception calling "Load" with ...
Read more >
Unable to load Windows.Markup.XamlReader - Stack Overflow
The code makes this output error: Unable to load Windows.Markup.XamlReader. This code is made by Microsoft Visual Studio - Project WPF APP
Read more >
WPF Xaml - PowerShell - Spiceworks Community
Xml.XmlNodeReader $Form) $Win=[Windows.Markup.XamlReader]::Load( $NR ) ... to type "System. ... + FullyQualifiedErrorId : RuntimeException
Read more >
Learn Powershell | Achieve More | Page 47 - Learn Powershell
Top = '50'/> </Canvas> </Window> "@ $reader=(New-Object System.Xml.XmlNodeReader $xaml) $Window=[Windows.Markup.XamlReader]::Load( $reader ) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found