-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Can't import v1.0.2 to pwsh.exe v7.4.1 with error "Import-Module: Assembly with same name is already loaded" #21201
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
Comments
Seems it has something to do with PSResourceGet v1.0.1 being included in PowerShell v7.4.1. I deleted the whole |
It also works as expected if adding a version directory to the v7.4.1 included PSResourceGet. So was originally:
Became:
Additional info:
This might be an issue with how And PScriptAnalyzer might be relevant here too? Simply opening a given script in VSCode loads PSResourceGet assemblies. I think this can be a related issue: |
Can you run |
PowerShell 7.4.1
PS C:\Users\olavb> Get-Module
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 2.3.4 PSReadLine {Get-PSReadLineKeyHandler, Get-PSReadLineOption, …
PS C:\Users\olavb> I could repro with another module too, so does not seem to be the issue of PSResourceGet? |
@o-l-a-v Thanks for the info, we're going to send this over to PowerShell/PowerShell |
The issue is about loading modules and not specific to PowerShellResourceGet. Transferring over to PowerShell/PowerShell repository. |
Here is an easy and reliable repro of this issue. Prerequisite: Module of lower version must not be inside a versioned folder.
Does not repro:
Does repro:
Repro:
# Set PSModulePath in process scope
$env:PSModulePath = (
'{0}\ModulesFirstNotVersioned\Modules1;{0}\ModulesFirstNotVersioned\Modules2' -f
[System.Environment]::GetFolderPath('Desktop')
)
# Import Microsoft.PowerShell.PSResourceGet v1.1.0
Import-Module -Name 'Microsoft.PowerShell.PSResourceGet' -RequiredVersion 1.1.0 -Verbose -Debug This gives: PS > Import-Module -Name 'Microsoft.PowerShell.PSResourceGet' -RequiredVersion 1.1.0 -Verbose -Debug
VERBOSE: Loading module from path 'C:\Users\olavb\Desktop\ModulesFirstNotVersioned\Modules1\Microsoft.PowerShell.PSResourceGet\Microsoft.PowerShell.PSResourceGet.psd1'.
VERBOSE: Loading module from path 'C:\Users\olavb\Desktop\ModulesFirstNotVersioned\Modules2\Microsoft.PowerShell.PSResourceGet\1.1.0\Microsoft.PowerShell.PSResourceGet.psd1'.
VERBOSE: Loading 'FormatsToProcess' from path 'C:\Users\olavb\Desktop\ModulesFirstNotVersioned\Modules2\Microsoft.PowerShell.PSResourceGet\1.1.0\PSGet.Format.ps1xml'.
VERBOSE: Loading module from path 'C:\Users\olavb\Desktop\ModulesFirstNotVersioned\Modules2\Microsoft.PowerShell.PSResourceGet\1.1.0\Microsoft.PowerShell.PSResourceGet.psm1'.
VERBOSE: Exporting function 'Import-PSGetRepository'.
VERBOSE: Importing function 'Import-PSGetRepository'.
VERBOSE: Loading module from path 'C:\Users\olavb\Desktop\ModulesFirstNotVersioned\Modules2\Microsoft.PowerShell.PSResourceGet\1.1.0\Microsoft.PowerShell.PSResourceGet.dll'.
Import-Module: Could not load file or assembly 'Microsoft.PowerShell.PSResourceGet, Version=1.1.0.1, Culture=neutral, PublicKeyToken=null'. Assembly with same name is already loaded
PS > |
I also run into this frequently and I have no idea how to solve it.
The |
Trying to add some insight, this is my understanding: Background:PowerShell is supposed to be able to manage module versions side-by-side, loading the appropriate version as required. This is problematic for versioned modules that depends on versioned assemblies like so
Because once the modulename +assembly is loaded at one version, there's no way to switch to a different version in that session, that's what Import-Module version searching bug?I think the @o-l-a-v has rightly identified that there is something defficent in the version searching / loading logic. My suspicion is that for modules in versioned subfolders (e.g. ^ I'm hoping someone else can anaylse and confirm or disprove my suspcion. @danielniccoliNote, whilst your error has similarities I suspect your error is just down to a bad/mixed install of Microsoft.Graph components. |
Uh oh!
There was an error while loading. Please reload this page.
Prerequisites
Steps to reproduce
Microsoft.PowerShell.PSResourceGet
v1.0.2.Using pwsh.exe v7.4.1
Microsoft.PowerShell.PSResourceGet' -RequiredVersion 1.0.2 -Verbose -Debug
Using VSCode
vscode-powershell
extension v2024.0.0 and PowerShell v7.4.1Import-Module -Name 'Microsoft.PowerShell.PSResourceGet' -RequiredVersion 1.0.2 -Verbose -Debug
in the PowerShell terminal inside VSCodeExpected behavior
Module should load without problems, without workarounds like having to modify PSModulePath in process context to put preferred module directory first.
Actual behavior
Error details
Environment data
Visuals
No response
The text was updated successfully, but these errors were encountered: