Why can't powershell 6 aka pwsh.exe load System.Windows.Forms

1

I have two different versions of powershell on my machine.

  • powershell.exe 5.1.18362.145
  • pwsh.exe 6.2.3

With powershell.exe I can execute

[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$oReturn=[System.Windows.Forms.Messagebox]::Show("This is the Message text")

But with pwsh.exe I get the error

Exception calling "LoadWithPartialName" with "1" argument(s): "Could not load file or assembly 'System.Windows.Forms, Culture=neutral, PublicKeyToken=null'. Operation is not supported. (Exception from HRESULT: 0x80131515)"
At line:1 char:2
+  [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Fo ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileLoadException

What's up here? Every time I opened powershell over the last 6 months I was shell spammed and told to upgrade to powershell 6. Now I have and the above doesn't work.

.net
winforms
powershell
asked on Stack Overflow Nov 29, 2019 by bradgonesurfing

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0