I'm working on a script with a GUI controlled by a PS class. I created a XAML file in VS and am trying to import the XAML. There is a method that imports, formats and loads the xaml file.
I have a similar script, that uses a XAML file too and I have no issues there, but it is based on functions.
The XAML file is the same in both cases.
But somehow it seems like the class script is not importing the assembly.
When I execute the script I get the following error:
Line |
25 | $this.MainWindow = [Windows.Markup.XamlReader]::Load($this.XM …
| ~~~~~~~~~~~~~~~~~~~~~~~~~
| Unable to find type [Windows.Markup.XamlReader]
At the moment the function looks like this:
`
#XAML import above...
Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName System.Windows.Forms
$this.MainWindow = [Windows.Markup.XamlReader]::Load($XMLUserCreateReader)
`
What I tried:
- I tried the
Add-Type
functions at the beginning of the script and in front of the method execution. - I also tried
[System.Reflection.Assembly]::LoadWithPartialName("PresentationFramework") | Out-Null
at all the mentioned positions... - Googled but everytime the problem was saolved with the
LoadWithPartialName
or the person forgot to import the assembly.
In my other script I have the same code, and it is working, why is it not working here?
Any suggestions what I could try next? Or where the problem could be?
Thanks :)