Psreadline: Upgrade of the PSReadLine fails due that `The version '2.0.0' of module 'PSReadLine' is currently in use.`

Created on 25 Feb 2020  路  24Comments  路  Source: PowerShell/PSReadLine

Environment

PS version: 6.2.4
PSReadline version: 2.0.0-beta3
os: Linux <hostname> 5.3.0-40-generic #32~18.04.1-Ubuntu SMP Mon Feb 3 14:05:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
PS file version: 6.2.4.0
HostName: ConsoleHost
BufferWidth: 205
BufferHeight: 26

Exception report

Nope

Steps to reproduce

I try to update the PSReadLine module by the following instruction from the README

If you are using the version of PSReadLine that ships with PowerShell 6+ versions, you need to run: -noprofile -command "Install-Module PSReadLine -Force -SkipPublisherCheck -AllowPrerelease".

The return is

WARNING: The version '2.0.0' of module 'PSReadLine' is currently in use. Retry the operation after closing the applications.

When I try to do that from PowerShell console

<user_name>% pwsh
PowerShell 6.2.4
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS <folder_name>> get-module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   6.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object鈥
Script     2.0.0      PSReadLine                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHandler鈥

PS <folder_name>> remove-module psreadline
PS <folder_name>> get-module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   6.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object鈥

PS <folder_name>> Install-Module PSReadline -Force 
WARNING: The version '2.0.0' of module 'PSReadLine' is currently in use. Retry the operation after closing the applications.                                                                                 PS <folder_name>>

Expected behavior

The module will be installed from the PowerShell Gallery.

Actual behavior

As described in the 'Steps to reproduce' section.

Resolution-External

Most helpful comment

@iSazonov I'm pretty confident Save-Module -Path <specifiedmodulespath> would be a suitable workaround. @it-praktyk could you let us know if this does in fact work for you?

All 24 comments

From the Upgrading section of README.md:

When running one of the suggested commands below, be sure to exit all instances of powershell.exe, pwsh.exe or pwsh, then run the suggested command from cmd.exe, powershell_ise.exe, or via the Win+R shortcut to make sure PSReadLine isn't loaded.
...

You need to close all powershell instances and then run <path-to-pwsh-executable> -noprofile -command "Install-Module PSReadLine -Force -SkipPublisherCheck -AllowPrerelease".
Unloading the module doesn't unload the assembly from the PSReadLine module (by design in .NET), hence you need to close all instances.

@daxian-dbw , please read the issue once again carefully.

PSReadLine is loaded (probably in background) by modules used to perform installation.

Please reopen my issue.

Thank you.

In your repro, you are installing PSReadline within an interactive pwsh instance.
For an interactive pwsh instance, PSReadLine is loaded at startup and its assemblies cannot be unloaded even if you remove the PSReadLine module. Therefore, Install-Module cannot remove those assemblies and thus believe the module is still in use.

Make sure you follow the upgrading instructions to install newer versions of PSReadLine.

My repro confirms that unloaded PSReadLine is loaded under Install-Module and then blocks installation.

Maybe I was not strict enough with explaining. I tried proposed upgrade procedure too.

Please take a loog on the screenshot below.

Selection_005

Thanks for clarifying your repro steps.

Now this looks like an issue with the Install-Module cmdlet, and I cannot repro locally with my Ubuntu machine.
@alerickson @SydneyhSmith does this look familiar to you?

Don't you need to run pwsh with the -noninteractive (sp?) switch for it to skip loading PSReadline (which it normally does as one of the first things in the session iirc).

@vexx32 When running -command without -noexit, PowerShell won't load PSReadLine, see the following example:

C:\>f:\pscore70.6\pwsh.exe -noprofile -command "Get-Module; 'no module loaded'"
no module loaded

-NonInteractive and -NoExit doesn't work either.

Selection_007

@it-praktyk @daxian-dbw that's not an issue I've seen before. As a work around, you can always use Save-Module and specify the module directory as the -path to install to.

@alerickson This is on Linux. On Linux, Install-Module should be able to remove the assemblies from disk even if the assemblies are loaded into memory by another process.
So I'm really confused about what might cause Install-Module to write out this warning.

Maybe this issue should be transferred to https://github.com/powershell/powershellget ?

@daxian-dbw Yes, please transfer to PowerShellGet.
It looks like PSGet tries to open a file to test whether the module is in use that's failing. @it-praktyk can you try running the following (with $FilePath being the path of the PSReadLine .psm1):

$fileInfo = New-Object System.IO.FileInfo $FilePath
$fileStream = $fileInfo.Open( [System.IO.FileMode]::Open, [System.IO.FileAccess]::ReadWrite, [System.IO.FileShare]::None )

@SteveL-MSFT Can you please help transfer this issue to the https://github.com/powershell/powershellget repository?

If it is Install-Module issue we need to find and document a workaround in PSRadline repo if possible. Otherwise we get a lot of new issues opened in the repo :-)

@iSazonov I'm pretty confident Save-Module -Path <specifiedmodulespath> would be a suitable workaround. @it-praktyk could you let us know if this does in fact work for you?

I was able to save the PSReadLine module locally using the Save-Module command and Import it explicitly from the folder where

As a part of a documented workaround, I propose to add information about (one of them):

  • moving dowloaded module to the correct directory
  • updating a value of the PSModulePath variable
  • importing a module from explicitly provided directory.

I've checked today - after upgrading to PSCore 7.0 - the issue still exists.

BTW, can you relabel the issue?

This issue is really about Install-Module and should be moved to the PowerShellGet repository.
Again, I cannot reproduce this on my Ubuntu ... 馃槮
@SteveL-MSFT Can you please help transfer this issue to PowerShellGet? @alerickson and I cannot do it ourselves.

As for a workaround, we plan to publish version 2.0.1 with the same bits as in 2.0.0, so installing the latest module will be put in a 2.0.1 folder side-by-side with 2.0.0.

@daxian-dbw - When moving from 1.2 to 2.0 - I changed the name of the DLL from Microsoft.PowerShell.PSReadLine.dll to Microsoft.PowerShell.PSReadLine2.dll to mitigate this issue somewhat.

I think the dll name could go back to the original name now since most systems have been using preview releases of 2.0.

I temporarily moved the C:\Program Files\WindowsPowerShell\Modules\PSReadline
Ran the Install-Module command and moved it back. This seemed to work.

When i try to install the preview i get the following error:
image

have no PowerShell instances open all closed and i am administrator on machine and using elevated privileges

@aavdberg Another bizarre instance of the problem. And again, I cannot reproduce on my Windows machine ... (see the screenshot below)

@aavdberg Can you please open an issue in https://github.com/powershell/powershellget? Please describe the context of your environment, such as what previous version of PSReadLine were installed, at what location.

image

Thank you @daxian-dbw made the following issue.

https://github.com/PowerShell/PowerShellGet/issues/108

If I run this command from pwsh, I see that PSReadline is running in the below directory
PS C:\Windows\System32> get-module psreadline|select-object -Property path
Path

C:program filespowershell\7\ModulesPSReadLinePSReadLine.psm1

If I go to C:program filespowershell\7\Modules and rename PSReadLine to PSReadLine.old

And then restart pwsh

And Run:

PS C:\Windows\System32> get-module psreadline|select-object -Property path
Path

C:\Program Files\WindowsPowerShell\ModulesPSReadLine2.0.1PSReadLine.psm1

Maybe this is connected to the issue?
A pyrrhic win of sorts in that PSReadLine 2.0.1 is loaded now.

Was this page helpful?
0 / 5 - 0 ratings