OneGet / oneget

PackageManagement (aka OneGet) is a package manager for Windows
MIT License
2.38k stars 189 forks source link

Unable to import PackageManagement module 1.4.8 #533

Open vvkjndl opened 2 years ago

vvkjndl commented 2 years ago
PS C:\Users\vmadmin> Get-PSRepository
Get-PSRepository : The 'Get-PSRepository' command was found in the module 'PowerShellGet', but the module could not be
loaded. For more information, run 'Import-Module PowerShellGet'.
At line:1 char:1
+ Get-PSRepository
+ ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-PSRepository:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

PS C:\Users\vmadmin> Get-PSRepository
PackageManagement\Get-PackageSource : The term 'PackageManagement\Get-PackageSource' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and
try again.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.5\PSModule.psm1:9539 char:31
+ ...         $packageSources = PackageManagement\Get-PackageSource @PSBoun ...
+                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (PackageManagement\Get-PackageSource:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

New-ModuleSourceFromPackageSource : Cannot bind argument to parameter 'PackageSource' because it is null.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.5\PSModule.psm1:9541 char:123
+ ... orEach-Object { New-ModuleSourceFromPackageSource -PackageSource $_ }
+                                                                      ~~
    + CategoryInfo          : InvalidData: (:) [New-ModuleSourceFromPackageSource], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,New-ModuleSourceFromPackageSource

PS C:\Users\vmadmin>
vvkjndl commented 2 years ago

Please let me know if any other details may be needed for reproducing or troubleshooting.

awickham10 commented 2 years ago

I'm having issues as well. Can't import PackageManagement or PowerShellGet modules. PowerShell 5.1.17763.2931.

PS C:\> Import-Module PackageManagement
Import-Module: Could not load file or assembly 'Microsoft.PackageManagement, Version=3.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A) At C:\Program Files\WindowsPowerShell\Modules\packagemanagement\1.4.8\PackageManagement.psm1:38 char:17 + $OneGetModule = Import-Module -name $OneGetModulePath -PassThru

I was able to revert to 1.4.7 and it resolved the issue for the server.

awickham10 commented 2 years ago

@alerickson can you take a look?

alerickson commented 2 years ago

Question for both of you, @vvkjndl and @awickham10, is this only when you explicitly run Import-Module? Do you have the same issue after starting a fresh session?

vvkjndl commented 2 years ago

Same issue persist in all prospective fresh sessions as long as 1.4.8 version of PackageManagement exists on system.

alerickson commented 2 years ago

@vvkjndl I found this issue online regarding the CouldNotAutoLoadMatchingModule error.
Can you set your execution policy to see if it's able to import?

Other info that would be helpful for debugging:

(If there's any private information here feel free to redact)

anamnavi commented 2 years ago

@awickham10 can you run the following and share output: run WindowsPowerShell in admin mode

$PSVersionTable Get-PSRepository Install-Module "PackageManagement" -RequiredVersion "1.4.8" -Repository "PSGallery" Import-Module "PackageManagement" -RequiredVersion "1.4.8" Get-PSRepository

deadlydog commented 2 years ago

I'm experiencing the same problem on many of our Windows Server 2016 servers that automatically updated to v1.4.8 of the PackageManagement module.

image

image

And here's the output of running the commands you asked @awickham10 to run above @anamnavi

PowerShell_transcript.20220628163306.txt

deadlydog commented 2 years ago

Considering this is a pretty debilitating bug (e.g. can't install, update, or remove modules), it may be worth trying to unlist v1.4.8 from the Gallery, or mark it as a preview, to prevent others from updating to it until this is resolved.

deadlydog commented 2 years ago

Thanks for unlisting PackageManagement v1.4.8 from the PowerShell Gallery so quickly team! 👍

Since PackageManagement v1.4.8 breaks the ability to use PowerShell to uninstall packages, I fixed up our servers by manually deleting the 1.4.8 module. You can check $env:PSModulePath to see where the module might be installed on your machine. For me it was located at C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.8, so I just deleted that directory and it got our servers back into a good state.

alerickson commented 2 years ago

I'm debugging right now and can't figure out what exactly is going on... I verified the strong name signature using sn.exe and the files appear to be valid.

@deadlydog can you run get-executionpolicy so I can have a little more context to your environment?

deadlydog commented 2 years ago

Our Execution Policy on that particular server is RemoteSigned.

I did a quick search in all our PowerShell modules for Microsoft.PackageManagement.dll, and the PackageManagement module versions are the only ones that contain it, so nothing else should be loading a different version into memory. Perhaps it's one of the Microsoft.PackageManagement.dll's dependencies that can't be loaded? Maybe a different version of the dependency is already in memory so it can't load the required version?

vvkjndl commented 2 years ago

My execution policy is Unrestricted.

I have several PowerShell scripts in my infrastructure that automatically updates the module to latest version.

Here's a workaround that I have applied on my servers:

begna112 commented 2 years ago

Piling on that I had this same issue. Windows Server 2016. Tried even a brand new Windows install and manually installing the packages. Same exact errors messages and lack of Exported Commands either with explicit or implicit imports.

vvkjndl commented 2 years ago

@vvkjndl I found this issue online regarding the CouldNotAutoLoadMatchingModule error. Can you set your execution policy to see if it's able to import?

Other info that would be helpful for debugging:

* The output of `gmo powershellget, packagemanagement -listavailable`

* Sharing the contents of the nuget.config file
  `Get-Content "$env:AppData\Roaming\NuGet\nuget.config" -raw`

(If there's any private information here feel free to redact)

@alerickson Information you asked for:

PS C:\Users\vmadmin> Get-Content -Path C:\Users\vmadmin\AppData\Roaming\NuGet\nuget.config -Raw
<?xml version="1.0"?>
<configuration>
  <packageSources>
  </packageSources>
</configuration>
PS C:\Users\vmadmin> gmo powershellget, packagemanagement -listavailable

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.4.7      PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...}
Binary     1.0.0.1    PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...}
Script     2.2.5      PowerShellGet                       {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability...}
Script     1.0.0.1    PowerShellGet                       {Install-Module, Find-Module, Save-Module, Update-Module...}

PS C:\Users\vmadmin> Get-ExecutionPolicy
Unrestricted
PS C:\Users\vmadmin>
alerickson commented 2 years ago

Okay, the issue with 1.4.8 was due to the strong name signing process in our pipeline. For some reason the strong name signature was showing as valid on Microsoft machines (probably a cert that's by default on our machines), but not on other machines. There's a fix for this and https://www.powershellgallery.com/packages/PackageManagement/1.4.8.1 should have a valid strong name signature for everyone now :smile:

Note: version 1.4.8.1 is unlisted right now, but still accessible if you find/install that exact version. I'll list again after the weekend.

awickham10 commented 1 year ago

Thanks for getting this resolved so quickly @alerickson! I provisioned several new servers yesterday, which pull the latest PackageManagement, and did not have any problems.