0

使用 PSReadLine 升级到 Powershell 7.2.0 后引发异常

### Environment
PSReadLine: 2.2.0-beta1
PowerShell: 7.2.0
OS: Microsoft Windows 10.0.22000
BufferWidth: 309
BufferHeight: 55

Last 0 Keys


System.TypeLoadException: Could not load type 'System.Management.Automation.Subsystem.PredictionResult' from assembly 'Microsoft.PowerShell.PSReadLine.Polyfiller, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
   at Microsoft.PowerShell.PSConsoleReadLine.PredictionViewBase.Reset()
   at Microsoft.PowerShell.PSConsoleReadLine.PredictionInlineView.Reset()
   at Microsoft.PowerShell.PSConsoleReadLine.Prediction.Reset()
   at Microsoft.PowerShell.PSConsoleReadLine.Initialize(Runspace runspace, EngineIntrinsics engineIntrinsics)
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken)
4

1 回答 1

2

该线程中所述,该问题可以通过以下方式解决

此问题已在 PSReadLine 的 2.2.0-beta3 版本中得到修复。您可以通过升级到 PSReadLine 的最新 2.2.0-beta4 版本来解决此问题。这样做的说明:

1:停止所有pwsh实例。

2:从 cmd.exe 运行:

pwsh -noprofile -command "Install-Module PSReadLine -AllowPrerelease -Force"

此外,如果您想卸载以前的设置,请按照

如果要删除 PSReadLine 的 beta 版本并使用 PowerShell 7.2 附带的 2.1.0 版本的 PSReadLine,您可以:

1:运行pwsh -noprofile -noninteractive启动pwsh而不加载PSReadLine

2:运行Uninstall-Module -Name PSReadLine -RequiredVersion <2.2.0-beta1 or 2.2.0-beta2> -AllowPrerelease删除模块。或者,您可以手动删除该模块文件夹。

于 2021-11-19T04:24:47.890 回答