You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unable to load Az modules - Assembly with same name is already loaded #4727
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
> $PSVersionTableName Value---- -----PSVersion 7.2.13PSEdition CoreGitCommitId 7.2.13OS 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 UnixPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}PSRemotingProtocolVersion 2.3SerializationVersion 1.1.0.1WSManStackVersion 3.0
Thanks Shawn Melton (@wsmelton) , to clarify is this a new issue for you or has this been happening on previous versions of the extension?
"If you load a PowerShell file that has references to Azure PowerShell commands the assemblies are being loaded without loading the module fully." We think this is happening from a Get-Help call in tab completion
It looks like the error itself may be coming from our resolve handler or something similar
Always happening since I started using an Apple device (M1), switched to this month ago. I can't recall if Windows device gives me this issue...I can test that shortly.
Extension versions I tried v2023.6.0 back to v2023.3.3, issue exist in all of them.
Your log said it loaded '/Users/smelton/ldx/Agents/ScriptAnalyzerSettings.psd1', is there anything in that file? Could be a bug that it found it but might be what's going on.
I'm seeing the same issue with Az.Accounts. And it's really annoying when that module is the best way to get authorization tokens to work with any of the Azure related Rest API's. Should we also report it as a bug for the Az module?
I'm seeing the same issue with Az.Accounts. And it's really annoying when that module is the best way to get authorization tokens to work with any of the Azure related Rest API's. Should we also report it as a bug for the Az module?
Same here, pain in the butt. No current workaround.
...I would highly suggest just hiding the Extension Terminal and using normal pwsh instances in the VS Code terminal pane (click the + button and you can also set powershell.integratedConsole.startInBackground to 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).
I'm seeing this issue with MS Graph SDK. Is there an idiot's guide to implementing Andy Jordan (@andyleejordan) recommendation? I found that when I want to Debug code the PIC is used regardless of having the powershell.integratedConsole.startInBackground to hide.
Paul Bendall (@PaulBendall) the issue has nothing to do with vscode specifically, basically what happens is that the Az modules have some common .NET libraries, and if one loads a lower version before another one that requires a higher version, that module will run into an error. It's even worse in PowerShell 5.1 vs 7 because assembly binding redirects aren't a thing.
It appears to happen more in vscode because the engine that makes vscode work, despite hiding some things properly, still has some common DLLs it has to load that might conflict
The best thing to do is to clean out all your Az modules, and then install specifically the ones you need at the same time with Install-PSResource to ensure you get the correct interdependencies, and then update all those modules together.
Also, you may have other modules loaded that use the same DLLs as Az (such as Azure.Identity). Ideally you load those in your system after Az and on Powershell 7+ so that binding redirects can work. Also keep your vscode extension up to date.
Could someone more knowledgeable than me about "proper assembly isolation" chime in in respective issues on how they should proceed to fix this? Is there a best practice reference guide? Or a reference module that does this right?
It's called an Assembly Load Context, and I believe Az already has it partially implemented but they use it to hide only one assembly which doesn't really do the trick :). Also this would be for PS7+ only, wouldn't work for PS5.1
It is very strange what Az does with their ALC. Some modules use it to hide a one (or a few) assemblies, some don't use it all. None of them use it correctly. Granted, "correct" is hard to get right with ALC and it's a ridiculous ask of module others, but is unfortunately just how .NET apps work.
Not a solution, but a workaround that may help some of you while we wait for a fix:
I am able to avoid the conflict between Microsoft.Graph and vscode's Powershell extension by using the PowerShell Launch Current File in Temporary Console
debug configuration instead of the PowerShell Launch Current File
debug configuration. I am not using Az, but it's not unlikely that the same workaround works for this module too.
Reacted by Andy Jordan and Olav Rønnestad Birkeland
Matthias Haldimann (@matthiashaldimann) that's a pretty good workaround as the temp console doesn't load PSES, so it won't have the same assembly conflicts.
Activity
SydneyhSmith commentedon Sep 6, 2023
Thanks Shawn Melton (@wsmelton) , to clarify is this a new issue for you or has this been happening on previous versions of the extension?
"If you load a PowerShell file that has references to Azure PowerShell commands the assemblies are being loaded without loading the module fully." We think this is happening from a
Get-Helpcall in tab completionIt looks like the error itself may be coming from our resolve handler or something similar
wsmelton commentedon Sep 6, 2023
Always happening since I started using an Apple device (M1), switched to this month ago. I can't recall if Windows device gives me this issue...I can test that shortly.
Extension versions I tried
v2023.6.0back tov2023.3.3, issue exist in all of them.wsmelton commentedon Sep 6, 2023
So I cannot replicate this on Windows (Windows 10, VS Code Insiders, PowerShell 7.2, and
v2023.9.1).andyleejordan commentedon Sep 6, 2023
Well, that's interesting. Usually it's the other way around (issue occurs on Windows but nowhere else).
wsmelton commentedon Sep 6, 2023
I'll grab diagnostic logs for the windows device I used tomorrow and upload them.
andyleejordan commentedon Sep 7, 2023
Shawn Melton (@wsmelton) could you share your PSSA settings file? We noticed:
and believe there is a PSSA rule that can cause modules to be imported when analyzing the file.
wsmelton commentedon Sep 7, 2023
There is no PSSA settings file in the referenced project
We have this in most of the project's settings.json file:
"powershell.scriptAnalysis.settingsPath": "./ScriptAnalyzerSettings.psd1"andyleejordan commentedon Sep 7, 2023
Your log said it loaded '/Users/smelton/ldx/Agents/ScriptAnalyzerSettings.psd1', is there anything in that file? Could be a bug that it found it but might be what's going on.
andyleejordan commentedon Sep 7, 2023
Oh wait nevermind also in the log:
And I misread that earlier.
11 remaining items
randriksen commentedon Nov 26, 2023
I'm seeing the same issue with Az.Accounts. And it's really annoying when that module is the best way to get authorization tokens to work with any of the Azure related Rest API's. Should we also report it as a bug for the Az module?
tropez1971 commentedon Nov 28, 2023
Same here, pain in the butt. No current workaround.
andyleejordan commentedon Nov 29, 2023
Yes please.
tropez1971 commentedon Nov 30, 2023
Found a workaround. If I do a forced update of both the Az.Storage and Az.Accounts modules, I’m back to working.
PaulBendall commentedon Mar 13, 2024
I'm seeing this issue with MS Graph SDK. Is there an idiot's guide to implementing Andy Jordan (@andyleejordan) recommendation? I found that when I want to Debug code the PIC is used regardless of having the
powershell.integratedConsole.startInBackgroundto hide.lbouriez commentedon Jun 7, 2024
I am trying to do a remove and import of these 2 but I still get the issue. Can you post your workaround, maybe i am missing something
JustinGrote commentedon Jun 10, 2024
Paul Bendall (@PaulBendall) the issue has nothing to do with vscode specifically, basically what happens is that the Az modules have some common .NET libraries, and if one loads a lower version before another one that requires a higher version, that module will run into an error. It's even worse in PowerShell 5.1 vs 7 because assembly binding redirects aren't a thing.
It appears to happen more in vscode because the engine that makes vscode work, despite hiding some things properly, still has some common DLLs it has to load that might conflict
The best thing to do is to clean out all your Az modules, and then install specifically the ones you need at the same time with
Install-PSResourceto ensure you get the correct interdependencies, and then update all those modules together.Also, you may have other modules loaded that use the same DLLs as Az (such as Azure.Identity). Ideally you load those in your system after Az and on Powershell 7+ so that binding redirects can work. Also keep your vscode extension up to date.
That's the best advice I can offer.
o-l-a-v commentedon Oct 1, 2024
I made an issue in both the Azure PowerShell (
Az) and the Microsoft Graph SDK PowerShell (Microsoft.Graph) repos.Az: Implement proper assembly isolation to play nice withvscode-powershellAzure/azure-powershell#26206Microsoft.Graph: Implement proper assembly isolation to play nice withvscode-powershellmicrosoftgraph/msgraph-sdk-powershell#2978Could someone more knowledgeable than me about "proper assembly isolation" chime in in respective issues on how they should proceed to fix this? Is there a best practice reference guide? Or a reference module that does this right?
Edit: Other modules:
PnP.PowerShell:Edit 2: Created PowerShell discussion about this topic:
JustinGrote commentedon Oct 1, 2024
It's called an Assembly Load Context, and I believe Az already has it partially implemented but they use it to hide only one assembly which doesn't really do the trick :). Also this would be for PS7+ only, wouldn't work for PS5.1
https://learn.microsoft.com/en-us/dotnet/api/system.runtime.loader.assemblyloadcontext?view=net-8.0
andyleejordan commentedon Oct 1, 2024
It is very strange what Az does with their ALC. Some modules use it to hide a one (or a few) assemblies, some don't use it all. None of them use it correctly. Granted, "correct" is hard to get right with ALC and it's a ridiculous ask of module others, but is unfortunately just how .NET apps work.
o-l-a-v commentedon Oct 2, 2024
As Microsoft seems to be focusing on security lately for many projects: Can ALC be an argument for better security?
matthiashaldimann commentedon Oct 6, 2024
Not a solution, but a workaround that may help some of you while we wait for a fix:
I am able to avoid the conflict between Microsoft.Graph and vscode's Powershell extension by using the
PowerShell Launch Current File in Temporary Console
debug configuration instead of the
PowerShell Launch Current File
debug configuration. I am not using Az, but it's not unlikely that the same workaround works for this module too.
JustinGrote commentedon Oct 6, 2024
Matthias Haldimann (@matthiashaldimann) that's a pretty good workaround as the temp console doesn't load PSES, so it won't have the same assembly conflicts.
SamErde commentedon Mar 12, 2026
I just released v1.0 of my DLL Pickle module that prevents most cases of these DLL version conflicts. Please try it out and let me know your results!