vscode-powershell: Unable to load Az modules - Assembly with same name is already loaded
Prerequisites
- I have written a descriptive issue title.
- I have searched all open and closed issues to ensure it has not already been reported.
- I have read the troubleshooting guide.
- I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
- I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
- If this is a security issue, I have read the security issue reporting guidance.
Summary
If you load a PowerShell file that has references to Azure PowerShell commands the assemblies are being loaded without loading the module fully.
This is repeat of #3012 which was closed with no solution. Extensions do not matter in this case, it is when a file that has Azure module references is opened the assemblies get loaded but not the actual modules.
PowerShell Version
> $PSVersionTable
Name Value
---- -----
PSVersion 7.2.13
PSEdition Core
GitCommitId 7.2.13
OS Darwin 21.6.0 Darwin Kernel Version 21.6.0: Thu Jul 6 22:20:00 PDT 2023; root:xnu-8020.240.18.702.13~1/RELEASE_A…
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visual Studio Code Version
> code-insiders --version
1.82.0-insider
f1302be1e67e3af5fbeb8bbb2ea784de7bc96150
arm64
Extension Version
> code --list-extensions --show-versions | Select-String powershell
ms-vscode.powershell@2023.6.0
Steps to Reproduce
- Close all PowerShell files
- Restart session for PowerShell Extension
- Run following command to list loaded assemblies
[System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object Location | Sort-Object -Property FullName | Select-Object -Property FullName, Location, GlobalAssemblyCache, IsFullyTrusted | Where FullName -like '*azure*' | ft
- Note nothing is returned
- Run
Get-Module Az* - Nothing is returned
- Open file (any file) with Az PowerShell references
- Rerun step 3
- All assemblies for the Az.Accounts and related commands are loaded
- Rerun step 5
- Nothing is returned
- Run
Import-Module Az.Accounts - Error returned:
Import-Module: Assembly with same name is already loaded
Visuals
https://github.com/PowerShell/vscode-powershell/assets/11204251/113bb121-5cd8-482d-847b-184bb594cb84
Logs
About this issue
- Original URL
- State: open
- Created 10 months ago
- Comments: 24 (9 by maintainers)
This is kind of just a known issue with the
Azsuite of modules; they do not implement assembly isolation correctly across the board and so run into assembly conflicts in various configurations. These issues show up everywhere, but more often with the Extension Terminal because we have more dependencies loaded underneath to support the LSP server (and the way the assembly isolation works requires both parties to be doing it correctly, 100% of the time, we gave a whole talk on this at PSConfEU this summer). I would highly suggest just hiding the Extension Terminal and using normalpwshinstances in the VS Code terminal pane (click the+button and you can also setpowershell.integratedConsole.startInBackgroundto hide the Extension Terminal at startup and just let it server its primary purpose in the background, which is powering the extension’s features by hosting an LSP server).Found a workaround. If I do a forced update of both the Az.Storage and Az.Accounts modules, I’m back to working.
I’ll grab diagnostic logs for the windows device I used tomorrow and upload them.