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 load Az modules - Assembly with same name is already loaded #4727

Open
6 tasks done
wsmelton opened this issue Sep 5, 2023 · 24 comments
Open
6 tasks done

Comments

@wsmelton
Copy link

wsmelton commented Sep 5, 2023

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

  1. Close all PowerShell files
  2. Restart session for PowerShell Extension
  3. 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
  1. Note nothing is returned
  2. Run Get-Module Az*
  3. Nothing is returned
  4. Open file (any file) with Az PowerShell references
  5. Rerun step 3
  6. All assemblies for the Az.Accounts and related commands are loaded
  7. Rerun step 5
  8. Nothing is returned
  9. Run Import-Module Az.Accounts
  10. Error returned: Import-Module: Assembly with same name is already loaded

Visuals

VSCode-PowerShell-Az.mp4

Logs

ext_logs.zip

@wsmelton wsmelton added the Issue-Bug A bug to squash. label Sep 5, 2023
@SydneyhSmith
Copy link
Collaborator

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

@wsmelton
Copy link
Author

wsmelton commented 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.0 back to v2023.3.3, issue exist in all of them.

@wsmelton
Copy link
Author

wsmelton commented Sep 6, 2023

So I cannot replicate this on Windows (Windows 10, VS Code Insiders, PowerShell 7.2, and v2023.9.1).

@andyleejordan
Copy link
Member

Well, that's interesting. Usually it's the other way around (issue occurs on Windows but nowhere else).

@wsmelton
Copy link
Author

wsmelton commented Sep 6, 2023

I'll grab diagnostic logs for the windows device I used tomorrow and upload them.

@andyleejordan
Copy link
Member

andyleejordan commented Sep 7, 2023

@wsmelton could you share your PSSA settings file? We noticed:

2023-09-05 08:05:03.512 -05:00 [VRB] Using Script Analyzer settings path - '/Users/smelton/ldx/Agents/ScriptAnalyzerSettings.psd1'.

and believe there is a PSSA rule that can cause modules to be imported when analyzing the file.

@wsmelton
Copy link
Author

wsmelton commented Sep 7, 2023

There is no PSSA settings file in the referenced project

image

We have this in most of the project's settings.json file:
"powershell.scriptAnalysis.settingsPath": "./ScriptAnalyzerSettings.psd1"

@andyleejordan
Copy link
Member

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

Oh wait nevermind also in the log:

[INF] Unable to find PSSA settings file at '/Users/smelton/ldx/Agents/ScriptAnalyzerSettings.psd1'. Loading default rules.

And I misread that earlier.

@andyleejordan
Copy link
Member

  • Open file (any file) with Az PowerShell references

@wsmelton Could you share a script you know to cause this issue? I have an M1 Mac available I can try to reproduce this on. If I can repro it, there's a really good chance I can fix it.

@wsmelton
Copy link
Author

So seems after updates (whether the extension pre-release or VS Code Insiders) I no longer see this issue. At least the steps I have written no longer show any errors.

@andyleejordan
Copy link
Member

@wsmelton...well, that's confusing, but good to know! Let us know if it crops up again. Thanks!

@geertvanzoest
Copy link

geertvanzoest commented Sep 20, 2023

Hi, I got the same problem as @wsmelton. Running Windows 10 Enterprise 22H2 the same problem occurs with both release and pre-release versions of the PowerShell-extension:

PS C:\> Import-Module Az.Keyvault -Verbose
VERBOSE: Loading module from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.Keyvault\4.11.0\Az.Keyvault.psd1'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.Keyvault\4.11.0\Microsoft.Azure.KeyVault.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.Keyvault\4.11.0\Microsoft.Azure.KeyVault.WebKey.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.Keyvault\4.11.0\Microsoft.Azure.PowerShell.KeyVault.Management.Sdk.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.Keyvault\4.11.0\Azure.Security.KeyVault.Keys.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.Keyvault\4.11.0\Azure.Security.KeyVault.Certificates.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.Keyvault\4.11.0\Azure.Security.KeyVault.Administration.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.Keyvault\4.11.0\BouncyCastle.Crypto.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.Keyvault\4.11.0\KeyVault.Autorest\bin\Az.KeyVault.private.dll'.
VERBOSE: Loading 'FormatsToProcess' from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.Keyvault\4.11.0\KeyVault.format.ps1xml'.
VERBOSE: Loading 'FormatsToProcess' from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.Keyvault\4.11.0\KeyVault.Autorest\Az.KeyVault.format.ps1xml'.
VERBOSE: Populating RepositorySourceLocation property for module Az.Keyvault.
VERBOSE: Loading module from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.Keyvault\4.11.0\Az.KeyVault.Extension\Az.KeyVault.Extension.psd1'.
VERBOSE: Importing function 'Get-Secret'.
VERBOSE: Importing function 'Get-SecretInfo'.
VERBOSE: Importing function 'Remove-Secret'.
VERBOSE: Importing function 'Set-Secret'.
VERBOSE: Importing function 'Test-SecretVault'.
VERBOSE: Loading module from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.Keyvault\4.11.0\KeyVault.Autorest\Az.KeyVault.psm1'.
Import-Module: Assembly with same name is already loaded
Write-Error: 
This module requires Az.Accounts version 2.7.5 or greater. For installation instructions, please see: https://learn.microsoft.com/powershell/azure/install-az-ps
Import-Module: The module to process 'C:\Users\*********\Documents\PowerShell\Modules\Az.Keyvault\4.11.0\KeyVault.Autorest\Az.KeyVault.psm1', listed in field 'NestedModules' of module manifest 'C:\Users\*********\Documents\PowerShell\Modules\Az.Keyvault\4.11.0\Az.Keyvault.psd1' was not processed because no valid module was found in any module directory.```

However, when I open a new terminal in VS Code using profile 'pwsh', the problem does not occur:

PS C:\> Import-Module Az.KeyVault -Verbose
VERBOSE: Loading module from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.KeyVault\4.11.0\Az.KeyVault.psd1'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.KeyVault\4.11.0\Microsoft.Azure.KeyVault.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.KeyVault\4.11.0\Microsoft.Azure.KeyVault.WebKey.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.KeyVault\4.11.0\Microsoft.Azure.PowerShell.KeyVault.Management.Sdk.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.KeyVault\4.11.0\Azure.Security.KeyVault.Keys.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.KeyVault\4.11.0\Azure.Security.KeyVault.Certificates.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.KeyVault\4.11.0\Azure.Security.KeyVault.Administration.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.KeyVault\4.11.0\BouncyCastle.Crypto.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.KeyVault\4.11.0\KeyVault.Autorest\bin\Az.KeyVault.private.dll'.
VERBOSE: Loading 'FormatsToProcess' from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.KeyVault\4.11.0\KeyVault.format.ps1xml'.
VERBOSE: Loading 'FormatsToProcess' from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.KeyVault\4.11.0\KeyVault.Autorest\Az.KeyVault.format.ps1xml'.
VERBOSE: Populating RepositorySourceLocation property for module Az.KeyVault.
VERBOSE: Loading module from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.KeyVault\4.11.0\Az.KeyVault.Extension\Az.KeyVault.Extension.psd1'.
VERBOSE: Loading module from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.KeyVault\4.11.0\Az.KeyVault.Extension\Az.KeyVault.Extension.psm1'.
VERBOSE: Exporting function 'Check-SubscriptionLogIn'.
VERBOSE: Exporting function 'Get-Secret'.
VERBOSE: Exporting function 'Get-ByteArray'.
VERBOSE: Exporting function 'Get-String'.
VERBOSE: Exporting function 'Get-SecureString'.
VERBOSE: Exporting function 'Get-PSCredential'.
VERBOSE: Exporting function 'Get-Hashtable'.
VERBOSE: Exporting function 'Set-Secret'.
VERBOSE: Exporting function 'Set-ByteArray'.
VERBOSE: Exporting function 'Set-String'.
VERBOSE: Exporting function 'Set-SecureString'.
VERBOSE: Exporting function 'Set-PSCredential'.
VERBOSE: Exporting function 'Set-Hashtable'.
VERBOSE: Exporting function 'Remove-Secret'.
VERBOSE: Exporting function 'Get-SecretInfo'.
VERBOSE: Exporting function 'Test-SecretVault'.
VERBOSE: Importing function 'Get-Secret'.
VERBOSE: Importing function 'Get-SecretInfo'.
VERBOSE: Importing function 'Remove-Secret'.
VERBOSE: Importing function 'Set-Secret'.
VERBOSE: Importing function 'Test-SecretVault'.
VERBOSE: Loading module from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.KeyVault\4.11.0\KeyVault.Autorest\Az.KeyVault.psm1'.
VERBOSE: Importing function 'Add-AzKeyVaultManagedHsmRegion'.
VERBOSE: Importing function 'Get-AzKeyVaultManagedHsmRegion'.
VERBOSE: Importing function 'Remove-AzKeyVaultManagedHsmRegion'.
VERBOSE: Importing function 'Test-AzKeyVaultManagedHsmNameAvailability'.
VERBOSE: Importing function 'Test-AzKeyVaultNameAvailability'.
VERBOSE: Loading module from path 'C:\Users\*********\Documents\PowerShell\Modules\Az.KeyVault\4.11.0\Az.KeyVault.psm1'.
VERBOSE: Exporting function 'Get-Secret'.
VERBOSE: Exporting function 'Get-SecretInfo'.
VERBOSE: Exporting function 'Remove-Secret'.
VERBOSE: Exporting function 'Set-Secret'.
VERBOSE: Exporting function 'Test-SecretVault'.
VERBOSE: Exporting function 'Add-AzKeyVaultManagedHsmRegion'.
VERBOSE: Exporting function 'Get-AzKeyVaultManagedHsmRegion'.
VERBOSE: Exporting function 'Remove-AzKeyVaultManagedHsmRegion'.
VERBOSE: Exporting function 'Test-AzKeyVaultManagedHsmNameAvailability'.
VERBOSE: Exporting function 'Test-AzKeyVaultNameAvailability'.
VERBOSE: Exporting function 'Test-DotNet'.
VERBOSE: Exporting function 'Preload-Assembly'.
VERBOSE: Exporting cmdlet 'Add-AzKeyVaultCertificate'.
VERBOSE: Exporting cmdlet 'Backup-AzKeyVaultCertificate'.
VERBOSE: Exporting cmdlet 'Add-AzKeyVaultCertificateContact'.
VERBOSE: Exporting cmdlet 'Get-AzKeyVaultCertificateContact'.
VERBOSE: Exporting cmdlet 'Remove-AzKeyVaultCertificateContact'.
VERBOSE: Exporting cmdlet 'Get-AzKeyVaultCertificate'.
VERBOSE: Exporting cmdlet 'Get-AzKeyVaultCertificateOperation'.
VERBOSE: Exporting cmdlet 'Import-AzKeyVaultCertificate'.
VERBOSE: Exporting cmdlet 'Get-AzKeyVaultCertificateIssuer'.
VERBOSE: Exporting cmdlet 'Remove-AzKeyVaultCertificateIssuer'.
VERBOSE: Exporting cmdlet 'Set-AzKeyVaultCertificateIssuer'.
VERBOSE: Exporting cmdlet 'New-AzKeyVaultCertificatePolicy'.
VERBOSE: Exporting cmdlet 'Set-AzKeyVaultCertificatePolicy'.
VERBOSE: Exporting cmdlet 'Remove-AzKeyVaultCertificate'.
VERBOSE: Exporting cmdlet 'Remove-AzKeyVaultCertificateOperation'.
VERBOSE: Exporting cmdlet 'Restore-AzKeyVaultCertificate'.
VERBOSE: Exporting cmdlet 'Stop-AzKeyVaultCertificateOperation'.
VERBOSE: Exporting cmdlet 'Undo-AzKeyVaultCertificateRemoval'.
VERBOSE: Exporting cmdlet 'Update-AzKeyVaultCertificate'.
VERBOSE: Exporting cmdlet 'Get-AzKeyVault'.
VERBOSE: Exporting cmdlet 'Add-AzKeyVaultKey'.
VERBOSE: Exporting cmdlet 'Backup-AzKeyVaultKey'.
VERBOSE: Exporting cmdlet 'Get-AzKeyVaultKey'.
VERBOSE: Exporting cmdlet 'Remove-AzKeyVaultKey'.
VERBOSE: Exporting cmdlet 'Restore-AzKeyVaultKey'.
VERBOSE: Exporting cmdlet 'Undo-AzKeyVaultKeyRemoval'.
VERBOSE: Exporting cmdlet 'Update-AzKeyVaultKey'.
VERBOSE: Exporting cmdlet 'Remove-AzKeyVaultManagedHsm'.
VERBOSE: Exporting cmdlet 'Undo-AzKeyVaultManagedHsmRemoval'.
VERBOSE: Exporting cmdlet 'Add-AzKeyVaultManagedStorageAccount'.
VERBOSE: Exporting cmdlet 'Backup-AzKeyVaultManagedStorageAccount'.
VERBOSE: Exporting cmdlet 'Get-AzKeyVaultManagedStorageAccount'.
VERBOSE: Exporting cmdlet 'Get-AzKeyVaultManagedStorageSasDefinition'.
VERBOSE: Exporting cmdlet 'Remove-AzKeyVaultManagedStorageAccount'.
VERBOSE: Exporting cmdlet 'Remove-AzKeyVaultManagedStorageSasDefinition'.
VERBOSE: Exporting cmdlet 'Restore-AzKeyVaultManagedStorageAccount'.
VERBOSE: Exporting cmdlet 'Set-AzKeyVaultManagedStorageSasDefinition'.
VERBOSE: Exporting cmdlet 'Undo-AzKeyVaultManagedStorageAccountRemoval'.
VERBOSE: Exporting cmdlet 'Undo-AzKeyVaultManagedStorageSasDefinitionRemoval'.
VERBOSE: Exporting cmdlet 'Update-AzKeyVaultManagedStorageAccount'.
VERBOSE: Exporting cmdlet 'Update-AzKeyVaultManagedStorageAccountKey'.
VERBOSE: Exporting cmdlet 'New-AzKeyVault'.
VERBOSE: Exporting cmdlet 'Remove-AzKeyVault'.
VERBOSE: Exporting cmdlet 'Remove-AzKeyVaultAccessPolicy'.
VERBOSE: Exporting cmdlet 'Backup-AzKeyVaultSecret'.
VERBOSE: Exporting cmdlet 'Get-AzKeyVaultSecret'.
VERBOSE: Exporting cmdlet 'Remove-AzKeyVaultSecret'.
VERBOSE: Exporting cmdlet 'Restore-AzKeyVaultSecret'.
VERBOSE: Exporting cmdlet 'Set-AzKeyVaultSecret'.
VERBOSE: Exporting cmdlet 'Undo-AzKeyVaultSecretRemoval'.
VERBOSE: Exporting cmdlet 'Update-AzKeyVaultSecret'.
VERBOSE: Exporting cmdlet 'Set-AzKeyVaultAccessPolicy'.
VERBOSE: Exporting cmdlet 'Undo-AzKeyVaultRemoval'.
VERBOSE: Exporting cmdlet 'Update-AzKeyVault'.
VERBOSE: Exporting cmdlet 'Add-AzKeyVaultNetworkRule'.
VERBOSE: Exporting cmdlet 'New-AzKeyVaultNetworkRuleSetObject'.
VERBOSE: Exporting cmdlet 'Remove-AzKeyVaultNetworkRule'.
VERBOSE: Exporting cmdlet 'Update-AzKeyVaultNetworkRuleSet'.
VERBOSE: Exporting cmdlet 'Export-AzKeyVaultSecurityDomain'.
VERBOSE: Exporting cmdlet 'Import-AzKeyVaultSecurityDomain'.
VERBOSE: Exporting cmdlet 'New-AzKeyVaultCertificateAdministratorDetail'.
VERBOSE: Exporting cmdlet 'New-AzKeyVaultCertificateOrganizationDetail'.
VERBOSE: Exporting cmdlet 'Get-AzKeyVaultCertificatePolicy'.
VERBOSE: Exporting cmdlet 'Backup-AzKeyVault'.
VERBOSE: Exporting cmdlet 'Restore-AzKeyVault'.
VERBOSE: Exporting cmdlet 'Get-AzKeyVaultManagedHsm'.
VERBOSE: Exporting cmdlet 'New-AzKeyVaultManagedHsm'.
VERBOSE: Exporting cmdlet 'Update-AzKeyVaultManagedHsm'.
VERBOSE: Exporting cmdlet 'Get-AzKeyVaultRoleAssignment'.
VERBOSE: Exporting cmdlet 'Get-AzKeyVaultRoleDefinition'.
VERBOSE: Exporting cmdlet 'New-AzKeyVaultRoleDefinition'.
VERBOSE: Exporting cmdlet 'New-AzKeyVaultRoleAssignment'.
VERBOSE: Exporting cmdlet 'Remove-AzKeyVaultRoleAssignment'.
VERBOSE: Exporting cmdlet 'Remove-AzKeyVaultRoleDefinition'.
VERBOSE: Exporting cmdlet 'Get-AzKeyVaultSetting'.
VERBOSE: Exporting cmdlet 'Update-AzKeyVaultSetting'.
VERBOSE: Exporting cmdlet 'Get-AzKeyVaultRandomNumber'.
VERBOSE: Exporting cmdlet 'Invoke-AzKeyVaultKeyOperation'.
VERBOSE: Exporting cmdlet 'Get-AzKeyVaultKeyRotationPolicy'.
VERBOSE: Exporting cmdlet 'Set-AzKeyVaultKeyRotationPolicy'.
VERBOSE: Exporting cmdlet 'Invoke-AzKeyVaultKeyRotation'.
VERBOSE: Exporting alias 'Set-AzKeyVaultCertificateAttribute'.
VERBOSE: Exporting alias 'Set-AzKeyVaultKey'.
VERBOSE: Exporting alias 'Set-AzKeyVaultKeyAttribute'.
VERBOSE: Exporting alias 'Set-AzKeyVaultSecretAttribute'.
VERBOSE: Exporting alias 'Set-AzKeyVaultRoleDefinition'.
VERBOSE: Importing cmdlet 'Add-AzKeyVaultCertificate'.
VERBOSE: Importing cmdlet 'Add-AzKeyVaultCertificateContact'.
VERBOSE: Importing cmdlet 'Add-AzKeyVaultKey'.
VERBOSE: Importing cmdlet 'Add-AzKeyVaultManagedStorageAccount'.
VERBOSE: Importing cmdlet 'Add-AzKeyVaultNetworkRule'.
VERBOSE: Importing cmdlet 'Backup-AzKeyVault'.
VERBOSE: Importing cmdlet 'Backup-AzKeyVaultCertificate'.
VERBOSE: Importing cmdlet 'Backup-AzKeyVaultKey'.
VERBOSE: Importing cmdlet 'Backup-AzKeyVaultManagedStorageAccount'.
VERBOSE: Importing cmdlet 'Backup-AzKeyVaultSecret'.
VERBOSE: Importing cmdlet 'Export-AzKeyVaultSecurityDomain'.
VERBOSE: Importing cmdlet 'Get-AzKeyVault'.
VERBOSE: Importing cmdlet 'Get-AzKeyVaultCertificate'.
VERBOSE: Importing cmdlet 'Get-AzKeyVaultCertificateContact'.
VERBOSE: Importing cmdlet 'Get-AzKeyVaultCertificateIssuer'.
VERBOSE: Importing cmdlet 'Get-AzKeyVaultCertificateOperation'.
VERBOSE: Importing cmdlet 'Get-AzKeyVaultCertificatePolicy'.
VERBOSE: Importing cmdlet 'Get-AzKeyVaultKey'.
VERBOSE: Importing cmdlet 'Get-AzKeyVaultKeyRotationPolicy'.
VERBOSE: Importing cmdlet 'Get-AzKeyVaultManagedHsm'.
VERBOSE: Importing cmdlet 'Get-AzKeyVaultManagedStorageAccount'.
VERBOSE: Importing cmdlet 'Get-AzKeyVaultManagedStorageSasDefinition'.
VERBOSE: Importing cmdlet 'Get-AzKeyVaultRandomNumber'.
VERBOSE: Importing cmdlet 'Get-AzKeyVaultRoleAssignment'.
VERBOSE: Importing cmdlet 'Get-AzKeyVaultRoleDefinition'.
VERBOSE: Importing cmdlet 'Get-AzKeyVaultSecret'.
VERBOSE: Importing cmdlet 'Get-AzKeyVaultSetting'.
VERBOSE: Importing cmdlet 'Import-AzKeyVaultCertificate'.
VERBOSE: Importing cmdlet 'Import-AzKeyVaultSecurityDomain'.
VERBOSE: Importing cmdlet 'Invoke-AzKeyVaultKeyOperation'.
VERBOSE: Importing cmdlet 'Invoke-AzKeyVaultKeyRotation'.
VERBOSE: Importing cmdlet 'New-AzKeyVault'.
VERBOSE: Importing cmdlet 'New-AzKeyVaultCertificateAdministratorDetail'.
VERBOSE: Importing cmdlet 'New-AzKeyVaultCertificateOrganizationDetail'.
VERBOSE: Importing cmdlet 'New-AzKeyVaultCertificatePolicy'.
VERBOSE: Importing cmdlet 'New-AzKeyVaultManagedHsm'.
VERBOSE: Importing cmdlet 'New-AzKeyVaultNetworkRuleSetObject'.
VERBOSE: Importing cmdlet 'New-AzKeyVaultRoleAssignment'.
VERBOSE: Importing cmdlet 'New-AzKeyVaultRoleDefinition'.
VERBOSE: Importing cmdlet 'Remove-AzKeyVault'.
VERBOSE: Importing cmdlet 'Remove-AzKeyVaultAccessPolicy'.
VERBOSE: Importing cmdlet 'Remove-AzKeyVaultCertificate'.
VERBOSE: Importing cmdlet 'Remove-AzKeyVaultCertificateContact'.
VERBOSE: Importing cmdlet 'Remove-AzKeyVaultCertificateIssuer'.
VERBOSE: Importing cmdlet 'Remove-AzKeyVaultCertificateOperation'.
VERBOSE: Importing cmdlet 'Remove-AzKeyVaultKey'.
VERBOSE: Importing cmdlet 'Remove-AzKeyVaultManagedHsm'.
VERBOSE: Importing cmdlet 'Remove-AzKeyVaultManagedStorageAccount'.
VERBOSE: Importing cmdlet 'Remove-AzKeyVaultManagedStorageSasDefinition'.
VERBOSE: Importing cmdlet 'Remove-AzKeyVaultNetworkRule'.
VERBOSE: Importing cmdlet 'Remove-AzKeyVaultRoleAssignment'.
VERBOSE: Importing cmdlet 'Remove-AzKeyVaultRoleDefinition'.
VERBOSE: Importing cmdlet 'Remove-AzKeyVaultSecret'.
VERBOSE: Importing cmdlet 'Restore-AzKeyVault'.
VERBOSE: Importing cmdlet 'Restore-AzKeyVaultCertificate'.
VERBOSE: Importing cmdlet 'Restore-AzKeyVaultKey'.
VERBOSE: Importing cmdlet 'Restore-AzKeyVaultManagedStorageAccount'.
VERBOSE: Importing cmdlet 'Restore-AzKeyVaultSecret'.
VERBOSE: Importing cmdlet 'Set-AzKeyVaultAccessPolicy'.
VERBOSE: Importing cmdlet 'Set-AzKeyVaultCertificateIssuer'.
VERBOSE: Importing cmdlet 'Set-AzKeyVaultCertificatePolicy'.
VERBOSE: Importing cmdlet 'Set-AzKeyVaultKeyRotationPolicy'.
VERBOSE: Importing cmdlet 'Set-AzKeyVaultManagedStorageSasDefinition'.
VERBOSE: Importing cmdlet 'Set-AzKeyVaultSecret'.
VERBOSE: Importing cmdlet 'Stop-AzKeyVaultCertificateOperation'.
VERBOSE: Importing cmdlet 'Undo-AzKeyVaultCertificateRemoval'.
VERBOSE: Importing cmdlet 'Undo-AzKeyVaultKeyRemoval'.
VERBOSE: Importing cmdlet 'Undo-AzKeyVaultManagedHsmRemoval'.
VERBOSE: Importing cmdlet 'Undo-AzKeyVaultManagedStorageAccountRemoval'.
VERBOSE: Importing cmdlet 'Undo-AzKeyVaultManagedStorageSasDefinitionRemoval'.
VERBOSE: Importing cmdlet 'Undo-AzKeyVaultRemoval'.
VERBOSE: Importing cmdlet 'Undo-AzKeyVaultSecretRemoval'.
VERBOSE: Importing cmdlet 'Update-AzKeyVault'.
VERBOSE: Importing cmdlet 'Update-AzKeyVaultCertificate'.
VERBOSE: Importing cmdlet 'Update-AzKeyVaultKey'.
VERBOSE: Importing cmdlet 'Update-AzKeyVaultManagedHsm'.
VERBOSE: Importing cmdlet 'Update-AzKeyVaultManagedStorageAccount'.
VERBOSE: Importing cmdlet 'Update-AzKeyVaultManagedStorageAccountKey'.
VERBOSE: Importing cmdlet 'Update-AzKeyVaultNetworkRuleSet'.
VERBOSE: Importing cmdlet 'Update-AzKeyVaultSecret'.
VERBOSE: Importing cmdlet 'Update-AzKeyVaultSetting'.
VERBOSE: Importing function 'Add-AzKeyVaultManagedHsmRegion'.
VERBOSE: Importing function 'Get-AzKeyVaultManagedHsmRegion'.
VERBOSE: Importing function 'Remove-AzKeyVaultManagedHsmRegion'.
VERBOSE: Importing function 'Test-AzKeyVaultManagedHsmNameAvailability'.
VERBOSE: Importing function 'Test-AzKeyVaultNameAvailability'.
VERBOSE: Importing alias 'Set-AzKeyVaultCertificateAttribute'.
VERBOSE: Importing alias 'Set-AzKeyVaultKey'.
VERBOSE: Importing alias 'Set-AzKeyVaultKeyAttribute'.
VERBOSE: Importing alias 'Set-AzKeyVaultRoleDefinition'.
VERBOSE: Importing alias 'Set-AzKeyVaultSecretAttribute'.

The extension logfile:

9/20/2023 2:37:56 PM [NORMAL] - Visual Studio Code: v1.80.1 64-bit on Windows 64-bit
9/20/2023 2:37:56 PM [NORMAL] - PowerShell process started with PID: 4816
9/20/2023 2:37:56 PM [NORMAL] - PowerShell Extension: v2023.9.2
9/20/2023 2:37:56 PM [NORMAL] - Starting 'PowerShell (x64)' at: C:\Program Files\PowerShell\7\pwsh.exe
9/20/2023 2:38:02 PM [NORMAL] - Started PowerShell v7.3.7.
9/20/2023 2:38:03 PM [NORMAL] - PowerShell is up-to-date.

Any suggestions on how to proceed?

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.7
PSEdition                      Core
GitCommitId                    7.3.7
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}       
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
image

@geertvanzoest
Copy link

Alright. So this morning, the day after reporting the issue in this thread, the problem does not occur any longer. But unlike @wsmelton, I did not update anything. The only thing happening in between was a reboot 🙄

Ah, well... $Whatever | Float-YourGoat

@geertvanzoest
Copy link

Today, the same problem is back again, unfortunatelly:

Connect-AzAccount: 
Line |
   8 |  Connect-AzAccount
     |  ~~~~~~~~~~~~~~~~~
     | The 'Connect-AzAccount' command was found in the module 'Az.Accounts', but the module could not be loaded due to the following error: [Assembly with same name is already loaded]
For more information, run 'Import-Module Az.Accounts'.

Only thing that happened in between my posts is a shutdown/startup of the system. I don't receive this error with any other session of pwsh in VS Code or Windows Terminal - only with the PowerShell Extension in VS Code.

@andyleejordan
Copy link
Member

Have any of you had a chance to test with the latest pre-release, v2023.9.3-preview? It included a major OmniSharp update (which updated Newtonsoft.Json that was at least one of the conflicting problems).

@wsmelton
Copy link
Author

wsmelton commented Oct 3, 2023

I'm using the pre-release v2023.9.4 and beginning to see this again.

@wsmelton
Copy link
Author

wsmelton commented Oct 3, 2023

@andyleejordan happy to jump on a Teams call with the team if needed.

@andyleejordan
Copy link
Member

This is kind of just a known issue with the Az suite 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 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).

@andyleejordan andyleejordan pinned this issue Nov 10, 2023
@randriksen
Copy link

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

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.

@andyleejordan
Copy link
Member

Should we also report it as a bug for the Az module?

Yes please.

@tropez1971
Copy link

Found a workaround. If I do a forced update of both the Az.Storage and Az.Accounts modules, I’m back to working.

@PaulBendall
Copy link

...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 @andyleejordan recommendation? I found that when I want to Debug code the PIC is used regardless of having the powershell.integratedConsole.startInBackground to hide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Wishlist
Development

No branches or pull requests

7 participants