Repository navigation
Can't import v1.0.2 to pwsh.exe v7.4.1 with error "Import-Module: Assembly with same name is already loaded" #21201
Copy link
Copy link
Open
Labels
Needs-TriageThe issue is new and needs to be triaged by a work group.The issue is new and needs to be triaged by a work group.
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
Steps to reproduce
Using pwsh.exe v7.4.1
- Open pwsh.exe, enter
Microsoft.PowerShell.PSResourceGet' -RequiredVersion 1.0.2 -Verbose -Debug
Using VSCode
- Start a clean VSCode v1.86.0 session with
vscode-powershellextension v2024.0.0 and PowerShell v7.4.1 - Run
Import-Module -Name 'Microsoft.PowerShell.PSResourceGet' -RequiredVersion 1.0.2 -Verbose -Debugin the PowerShell terminal inside VSCode
Expected behavior
Module should load without problems, without workarounds like having to modify PSModulePath in process context to put preferred module directory first.
Actual behavior
PS C:\Users\olav.birkeland> Import-Module -Name 'Microsoft.PowerShell.PSResourceGet' -RequiredVersion 1.0.2 -Verbose -Debug
VERBOSE: Loading module from path 'C:\program files\powershell\7\Modules\Microsoft.PowerShell.PSResourceGet\Microsoft.PowerShell.PSResourceGet.psd1'.
VERBOSE: Loading module from path 'C:\Users\olav.birkeland\AppData\Local\Microsoft\PowerShell\Modules\Microsoft.PowerShell.PSResourceGet\1.0.2\Microsoft.PowerShell.PSResourceGet.psd1'.
VERBOSE: Loading 'FormatsToProcess' from path 'C:\Users\olav.birkeland\AppData\Local\Microsoft\PowerShell\Modules\Microsoft.PowerShell.PSResourceGet\1.0.2\PSGet.Format.ps1xml'.
VERBOSE: Loading module from path 'C:\Users\olav.birkeland\AppData\Local\Microsoft\PowerShell\Modules\Microsoft.PowerShell.PSResourceGet\1.0.2\Microsoft.PowerShell.PSResourceGet.psd1'.
VERBOSE: Loading 'FormatsToProcess' from path 'C:\Users\olav.birkeland\AppData\Local\Microsoft\PowerShell\Modules\Microsoft.PowerShell.PSResourceGet\1.0.2\PSGet.Format.ps1xml'.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.PowerShell.PSResourceGet.
VERBOSE: Loading module from path 'C:\Users\olav.birkeland\AppData\Local\Microsoft\PowerShell\Modules\Microsoft.PowerShell.PSResourceGet\1.0.2\Microsoft.PowerShell.PSResourceGet.psm1'.
VERBOSE: Exporting function 'Import-PSGetRepository'.
VERBOSE: Importing function 'Import-PSGetRepository'.
VERBOSE: Loading module from path 'C:\Users\olav.birkeland\AppData\Local\Microsoft\PowerShell\Modules\Microsoft.PowerShell.PSResourceGet\1.0.2\Microsoft.PowerShell.PSResourceGet.dll'.
Import-Module: Assembly with same name is already loaded
PS C:\Users\olav.birkeland>Error details
Exception :
Type : System.IO.FileLoadException
Message : Assembly with same name is already loaded
TargetSite :
Name : LoadBinaryModule
DeclaringType : Microsoft.PowerShell.Commands.ModuleCmdletBase
MemberType : Method
Module : System.Management.Automation.dll
Source : System.Management.Automation
HResult : -2146232799
StackTrace :
at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadBinaryModule(PSModuleInfo parentModule, String moduleName, String fileName, Assembly assemblyToLoad, String moduleBase, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, String prefix, Boolean& found, String shortModuleName, Boolean disableFormatUpdates)
at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(PSModuleInfo parentModule, String fileName, String moduleBase, String prefix, SessionState ss, Object privateData, ImportModuleOptions& options, ManifestProcessingFlags manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound)
at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleNamedInManifest(PSModuleInfo parentModule, ModuleSpecification moduleSpecification, String moduleBase, Boolean searchModulePath, String prefix, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, Object privateData, Boolean& found, String shortModuleName, Nullable`1 manifestLanguageMode)
at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleManifest(String moduleManifestPath, ExternalScriptInfo manifestScriptInfo, Hashtable data, Hashtable localizedData, ManifestProcessingFlags manifestProcessingFlags, Version minimumVersion, Version maximumVersion, Version requiredVersion, Nullable`1 requiredModuleGuid, ImportModuleOptions& options, Boolean& containedErrors)
at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(PSModuleInfo parentModule, String fileName, String moduleBase, String prefix, SessionState ss, Object privateData, ImportModuleOptions& options, ManifestProcessingFlags manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound)
at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadUsingExtensions(PSModuleInfo parentModule, String moduleName, String fileBaseName, String extension, String moduleBase, String prefix, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound)
at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadUsingMultiVersionModuleBase(String moduleBase, ManifestProcessingFlags manifestProcessingFlags, ImportModuleOptions importModuleOptions, Boolean& found)
at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadUsingModulePath(PSModuleInfo parentModule, IEnumerable`1 modulePath, String name, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, PSModuleInfo& module)
at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName(ImportModuleOptions importModuleOptions, String name)
at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName_WithTelemetry(ImportModuleOptions importModuleOptions, String name)
at Microsoft.PowerShell.Commands.ImportModuleCommand.ProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()
CategoryInfo : NotSpecified: (:) [Import-Module], FileLoadException
FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand
InvocationInfo :
MyCommand : Import-Module
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : 1
Line : Import-Module -Name 'Microsoft.PowerShell.PSResourceGet' -RequiredVersion 1.0.2 -Verbose -Debug
Statement : Import-Module -Name 'Microsoft.PowerShell.PSResourceGet' -RequiredVersion 1.0.2 -Verbose -Debug
PositionMessage : At line:1 char:1
+ Import-Module -Name 'Microsoft.PowerShell.PSResourceGet' -RequiredVer …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : Import-Module
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1Environment data
- Windows 11 23H2
- Visual Studio Code v1.86.0 x64
- vscode-powershell extension v2024.0.0
- Microsoft.PowerShell.PSResourceGet v1.0.3
- PowerShell v7.4.1 x64
Visuals
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Needs-TriageThe issue is new and needs to be triaged by a work group.The issue is new and needs to be triaged by a work group.
Activity
o-l-a-v commentedon Feb 8, 2024
Now I can't load it into
pwsh.exev7.4.1 either. 🤔But it works from
pwsh.exev7.2.18:[-]Can't import v1.0.2 to VSCode with error "Import-Module: Assembly with same name is already loaded"[/-][+]Can't import v1.0.2 to pwsh.exe v7.4.1 with error "Import-Module: Assembly with same name is already loaded"[/+]o-l-a-v commentedon Feb 8, 2024
Seems it has something to do with PSResourceGet v1.0.1 being included in PowerShell v7.4.1.
I deleted the whole
%ProgramW6432%\PowerShell\7\Modules\Microsoft.PowerShell.PSResourceGetdirectory, then v7.4.1 managed toImport-Module -Name 'Microsoft.PowerShell.PSResourceGet' -RequiredVersion 1.0.2.o-l-a-v commentedon Feb 8, 2024
It also works as expected if adding a version directory to the v7.4.1 included PSResourceGet. So was originally:
%ProgramW6432%\PowerShell\7\Modules\Microsoft.PowerShell.PSResourceGet\<content>Became:
%ProgramW6432%\PowerShell\7\Modules\Microsoft.PowerShell.PSResourceGet\1.0.1\<content>Additional info:
<modulename>\<version>\<content>).<modulename>\<version>\<content>.<modulename>\<content>instead of<modulename>\<version>\<content>.This might be an issue with how
Import-Moduleworks? Related issues: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:
alerickson commentedon Feb 8, 2024
Can you run
Get-Moduleafter starting a new session?o-l-a-v commentedon Feb 8, 2024
alerickson
I could repro with another module too, so does not seem to be the issue of PSResourceGet?
alerickson commentedon Feb 8, 2024
Olav Rønnestad Birkeland (@o-l-a-v) Thanks for the info, we're going to send this over to PowerShell/PowerShell
adityapatwardhan commentedon Feb 8, 2024
The issue is about loading modules and not specific to PowerShellResourceGet. Transferring over to PowerShell/PowerShell repository.
o-l-a-v commentedon Feb 8, 2025
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:
pwsh -NoProfileThis gives:
danielniccoli commentedon May 22, 2025
I also run into this frequently and I have no idea how to solve it.
The
.dllid loaded twice and the second time it displays an error.RPitt commentedon May 22, 2025
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.
However a fundamental limitation in the scheme is that PowerShell can't unload/reload .Net assemblies.
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
Assembly with same name is already loadedis saying.Import-Module version searching bug?
I think the Olav Rønnestad Birkeland (@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.
1.0.1\) PowerShell uses the folder name as quick indicator of the version whilst building a list of candidates.However for modules that are not in a versioned folder it seems to actually load the module even before it's determined if its the appropraite version.
This then causes the problem when it later tries to load the actually desired version and hits an error because the previous version is already loaded.
^ I'm hoping someone else can anaylse and confirm or disprove my suspcion.
Daniel Niccoli (@danielniccoli)
Note, whilst your error has similarities I suspect your error is just down to a bad/mixed install of Microsoft.Graph components.
Check your versions with
Get-Module -ListAvailable Microsoft.Graph*and if they're inconsistent I'd suggest uninstall/deleting them and re-installing Microsoft.Graph