After updates cannot run WPF code: Unable to find type [Windows.Markup.XamlReader]
See original GitHub issueFrom @music2myear on June 15, 2017 17:38
- VSCode Version: 1.13.1
- OS Version: Win10 1703 (OS Build 15063.413
- PowerShell Extension Version: 1.3.2
Steps to Reproduce:
WPF code not working.
Code:
[xml]$xaml = @"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="Window" Title="Initial Window" WindowStartupLocation = "CenterScreen"
Width = "800" Height = "600" ShowInTaskbar = "True">
</Window>
"@
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
$Window=[Windows.Markup.XamlReader]::Load( $reader )
Output:
Unable to find type [Windows.Markup.XamlReader]. At C:\path\script.ps1:12 char:9
- $Window=[Windows.Markup.XamlReader]::Load( $reader )
~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidOperation: (Windows.Markup.XamlReader:TypeName) [], RuntimeException
- FullyQualifiedErrorId : TypeNotFound
Running same code in PowerShell ISE works just fine.
Before issue began, three different installs occurred on my computer:
- VS Code updated from 1.13.0 to 1.13.1
- OS installed updates KB4022725 and KB4022405
- ATI Video Driver update included .NET 4.5 runtime
I have confirmed that .NET 4.7 is still loaded in system. PowerShell ISE runs same code just fine (simple window is displayed).
Copied from original issue: Microsoft/vscode#28827
Issue Analytics
- State:
- Created 6 years ago
- Comments:7
Top Results From Across the Web
Powershell can't load Windows.Markup.XamlReader
[Windows.Markup.XamlReader] requires the PresentationFramework assembly so add the following code at the beginning of your file: Add-Type ...
Read more >Error Windows.Markup.XamlReader Load
I'm trying to run default code after adding WPF window in VisualStudio 2019 ... [ERROR] Unable to find type [Windows.Markup.XamlReader].
Read more >Error when running XAML script with powershell - MSDN
I am trying to integrate WPF and powershell and run a simple XAML ... Xml.XmlNodeReader $Form) $Win=[Windows.Markup.XamlReader]::Load( $NR ) ...
Read more >XAMltest.ps1 1.0 - PowerShell Gallery
Write -Warning "We ran into a problem with the XAML code. ... Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is ......
Read more >A Customisable WPF MessageBox for PowerShell
Attempting to perform the InitializeDefaultDrives operation on the 'FileSystem' provider failed. New-Object : Cannot find type [System.Windows.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@daviwil Yes, prior to the updates noted in the OP I was able to run WPF code without issue. These and other tutorial scripts worked just fine pasting the code into a ps1 file in VS Code, saving, and executing in either the Powershell.exe or “PowerShell Integrated” terminals. Both worked the same and both ran WPF code.
Earlier today I thought there might have been an issue with PS on my computer and so just completed the standard Win10 corruption repair process including sfc /scannow, the full DISM health check, and a repair install when there were issues the other items were unable to resolve (checking the CBS logs showed these were not PowerShell-related, but apparently back checksums on .lnk files relevant to the RSAT tools).
Checking post-repair install I’m having the same issue.
All that out of the way, adding the Add-Type line you referenced appears to have done the trick.
I know this wasn’t being reference in my PS profiles, so I’m not sure how it was working before without this line being in the scripts somewhere, but they were.
As these scripts are intended for use somewhere besides my own computer, it makes sense for this line to be in the code, so perhaps having this problem now and you getting me the solution means it won’t be a surprise failure later.
I appreciate the information. We can consider this issue resolved.
Double the support, double the fun 😉