The following code runs fine when executed in ISE:
class MyWindow : Windows.Window {
}
# for testing purposes this is the whole script
But when run without ISE it results in an error:
At C:\Users\Thelonius\git\ps-scripts\minimal.ps1:1 char:18
+ class MyWindow : Windows.Window {
+ ~~~~~~~~~~~~~~
Unable to find type [Windows.Window].
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : TypeNotFound
When I run it in a new Powershell window by doing .\minimal.ps1
the error is the same. After executing Add-Type -AssemblyName PresentationFramework
in the shell .\minimal.ps1
runs without error. Since the error occurs while parsing the script adding the Add-Type
command to the script is no option. As I understand it instead using assembly PresentationFramework
should do the job. But it does not (neither in 5.0 nor in 5.1).
So is there a sane way to make it work without loading the assembly by Powershell command-line options or something similarly ugly?