为什么Powershell 6 aka pwsh.exe无法加载System.Windows.Forms

时间:2019-11-29 07:10:46

标签: .net winforms powershell

我的机器上有两个不同版本的Powershell。

  • powershell.exe 5.1.18362.145
  • pwsh.exe 6.2.3

使用powershell.exe我可以执行

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

但是用pwsh.exe我得到了错误

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

这是怎么回事?在过去的六个月中,每次打开powershell时,我都会遭到垃圾邮件攻击,并被告知要升级到powershell6。现在我可以了,以上都不起作用。

0 个答案:

没有答案