Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to import PackageManagement module 1.4.8 #533

Open
vvkjndl opened this issue Jun 28, 2022 · 17 comments
Open

Unable to import PackageManagement module 1.4.8 #533

vvkjndl opened this issue Jun 28, 2022 · 17 comments

Comments

@vvkjndl
Copy link

vvkjndl commented Jun 28, 2022

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
Copy link
Author

vvkjndl commented Jun 28, 2022

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

@awickham10
Copy link

awickham10 commented Jun 28, 2022

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
Copy link

@alerickson can you take a look?

@alerickson
Copy link
Collaborator

alerickson commented Jun 28, 2022

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
Copy link
Author

vvkjndl commented Jun 28, 2022

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

@alerickson
Copy link
Collaborator

alerickson commented Jun 28, 2022

@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)

@anamnavi
Copy link
Collaborator

anamnavi commented Jun 28, 2022

@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
Copy link

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
Copy link

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
Copy link

deadlydog commented Jun 28, 2022

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
Copy link
Collaborator

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
Copy link

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
Copy link
Author

vvkjndl commented Jun 29, 2022

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:

  • Let the module update to 1.4.8.
  • Copy the contents of 1.4.7 to 1.4.8 (C:\Program Files\WindowsPowerShell\Modules\PackageManagement\).
  • Disable the Modify/Write permissions to 1.4.8 directory.

@begna112
Copy link

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
Copy link
Author

vvkjndl commented Jun 29, 2022

@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
Copy link
Collaborator

alerickson commented Jul 1, 2022

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 😄

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants