Closed sgiovinetti closed 3 years ago
Connect-AzAccount: The 'Connect-AzAccount' command was found in the module 'Az.Accounts', but the module could not be loaded. For more information, run 'Import-Module Az.Accounts'.
Could you include the output of Import-Module Az.Accounts
please
@SeeminglyScience I can do even more :-)
> Import-Module Az.Accounts
> $Error[0].Exception | fl * -force
Message : Assembly with same name is already loaded FileName : FusionLog : TargetSite : Void Bind_LoadAssemblies(System.Management.Automation.ExecutionContext) StackTrace : at System.Management.Automation.Runspaces.InitialSessionState.Bind_LoadAssemblies(ExecutionContext context) at System.Management.Automation.Runspaces.InitialSessionState.Bind(ExecutionContext context, Boolean updateOnly, PSModuleInfo module, Boolean noClobber, Boolean local, Boolean setLocation) at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleManifest(String moduleManifestPath, ExternalScriptInfo manifestScriptInfo, Hashtable data, Hashtable localizedData, ManifestProcessingFlags manifestProcessingFlags, Version minimumVersion, Version maximumVersion, Version requiredVersion, Nullable1 requiredModuleGuid, ImportModuleOptions& options, Boolean&
containedErrors)
Data : {}
InnerException :
HelpLink :
Source : System.Management.Automation
HResult : -2146232799
Thanks! Can you see if it repros with the latest PowerShell 7.1 preview? That looks like the (fixed) PowerShell bug where it would try to load assemblies unnecessarily because they are listed in the FileList
manifest field (some of the at intellisense time autoloading that the extension does can make the bug more frequent).
@SeeminglyScience No way, the same also with Powershell 7.1 preview
Repro:
Open visual studio code with PS extension installed.
In the VS Code PS terminal run:
Connect-AzAccount
If you can provide the information requested in the issue template, that would be helpful
System Details Output
### VSCode version: 1.50.1 d2e414d9e4239a252d1ab117bd7067f125afd80a x64
### VSCode extensions:
azuredevspaces.azds@2.0.220200921
bibhasdn.random-string-password-generator@1.0.2
docsmsft.docs-yaml@0.2.5
hashicorp.terraform@2.2.3
humao.rest-client@0.24.3
ipedrazas.kubernetes-snippets@0.1.9
mindaro-dev.file-downloader@1.0.4
mindaro.mindaro@1.0.120201007
ms-azure-devops.azure-pipelines@1.174.2
ms-azuretools.vscode-azureappservice@0.19.0
ms-azuretools.vscode-azurefunctions@0.24.1
ms-azuretools.vscode-azureresourcegroups@0.2.0
ms-azuretools.vscode-azurestorage@0.10.1
ms-azuretools.vscode-azureterraform@0.3.1
ms-azuretools.vscode-azurevirtualmachines@0.2.0
ms-azuretools.vscode-cosmosdb@0.15.0
ms-azuretools.vscode-docker@1.6.0
ms-dotnettools.csharp@1.23.3
ms-dotnettools.vscode-dotnet-runtime@0.1.2
ms-kubernetes-tools.vscode-aks-tools@0.0.7
ms-kubernetes-tools.vscode-kubernetes-tools@1.2.1
ms-mssql.mssql@1.9.0
ms-python.python@2020.9.114305
ms-vscode-remote.remote-wsl@0.50.0
ms-vscode.azure-account@0.9.3
ms-vscode.azurecli@0.5.0
ms-vscode.powershell@2020.6.0
ms-vscode.vscode-node-azure-pack@0.0.11
ms-vsliveshare.vsliveshare@1.0.3014
ms-vsts.team@1.161.1
msazurermtools.azurerm-vscode-tools@0.13.0
Oracle.oracledevtools@19.3.3
redhat.vscode-yaml@0.11.1
run-at-scale.terraform-doc-snippets@0.4.0
sadeghpm.sql-snippets@0.0.4
samcogan.arm-snippets@1.4.19
sensourceinc.vscode-sql-beautify@0.0.4
Summer.azure-event-hub-explorer@0.1.2
tht13.python@0.2.3
VisualStudioExptTeam.vscodeintellicode@1.2.10
### PSES version: 2.2.0.0
### PowerShell version:
Name Value
---- -----
PSVersion 7.1.0-rc.1
PSEdition Core
GitCommitId 7.1.0-rc.1
OS Microsoft Windows 10.0.18363
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
I am experiencing a problem running Az module commands within VS Code powershell terminal
Running the command Connect-AzAccount
the message with code number and azure authentication procedure should appear
This error appears
Connect-AzAccount: The 'Connect-AzAccount' command was found in the module 'Az.Accounts', but the module could not be loaded. For more information, run 'Import-Module Az.Accounts'.
hmmmm @sgiovinetti did you get the same error manually importing the module with RC-1? Also do you have anything in your PowerShell profile or settings?
@SydneyhSmith : did you get the same error manually importing the module with RC-1? YES Also do you have anything in your PowerShell profile or settings? As far as I know I don't. Could you please be more specific? What in particular I need to check and how?
Thanks @sgiovinetti to get your PowerShell profile you can run psedit $profile
in the integrated console to view your settings in VSCode use Ctrl + ,
@SydneyhSmith
The result of $profile
is the following. Although I search in the full disk and wasn't able to find this file. Pressing Ctrl + in VSCode just zoom in the screen.
$profile
\PowerShell\Microsoft.VSCode_profile.ps1
psedit $profile
Get-ChildItem: C:\Users\giost\.vscode\extensions\ms-vscode.powershell-2020.6.0\modules\PowerShellEditorServices\Commands\Public\CmdletInterface.ps1:191:9
Line |
191 | Get-ChildItem $Paths -File | ForEach-Object {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
| Cannot find path 'D:\PowerShell\Microsoft.VSCode_profile.ps1' because it does not exist.
Try mkdir (Split-Path $profile)
and then try creating the profile
@rjmholt I don't think they need to do that. This proves there's nothing in the profile that could be showing this behavior. .
I am intrigued by the path not being a full path... That looks like it could cause issues based on what the current working directory is in relation to what drive you're on 😬
Out of curiosity: what does $profile | select *
output?
Pressing Ctrl + in VSCode just zoom in the screen.
@sgiovinetti I believe what Sydney was saying was try Ctrl + ,
to pull up the vscode settings. Once the settings are opened, there should be a button in the top left to "Open Settings (JSON)" that should show you if you have any settings that differ from the defaults.
@corbob
$profile | select *
AllUsersAllHosts : C:\Program Files\PowerShell\7-preview\profile.ps1
AllUsersCurrentHost : C:\Program Files\PowerShell\7-preview\Microsoft.VSCode_profile.ps1
CurrentUserAllHosts : \PowerShell\profile.ps1
CurrentUserCurrentHost : \PowerShell\Microsoft.VSCode_profile.ps1
Length : 40
I checked the settings.json and there is nothing there about powershell except
"powershell.powerShellDefaultVersion": "PowerShell Preview (x64)",
🤔 it's interesting that your User profiles are missing the Documents directory... The profile is usually stored in the PowerShell directory of: [environment]::GetFolderPath("MyDocuments")
C:\Users\corbob> [environment]::GetFolderPath("MyDocuments")
C:\Users\corbob\OneDrive\Documents
C:\Users\corbob> $profile | select *
AllUsersAllHosts : C:\Program Files\PowerShell\7\profile.ps1
AllUsersCurrentHost : C:\Program Files\PowerShell\7\Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts : C:\Users\corbob\OneDrive\Documents\PowerShell\profile.ps1
CurrentUserCurrentHost : C:\Users\corbob\OneDrive\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
Length : 78
Of course this is probably secondary to the originally reported issue...
@corbob : one detail that perhaps could be important. Our IT has setup the laptop so that the windows user settings reside on a mapped drive (NAS) that is not available when we work from home. I notice that when I connect to my company with the VPN and the mapped drive becomes available the vscode powershell intellisense tries to search for libraries on the mapped drive.
I guess the issue is in the vscode extension intellisense, I guess intellisense is trying to load some .net libraries located somewhere on my laptop or on network that goes in conflict with the Az module.
In fact I noticed that randomly, trying to open a fresh vs-code closing all the .ps files tab and opening a brand new empty .ps file sometimes it works.
So looking at things, it seems like two of the same assembly are somehow being loaded and the first one prevents the second one, which is the one from Az.Accounts, from being loaded.
The big question to my mind is: why and where is the first version of the assembly loaded and where from?
A couple of things that would help us answer that question:
Import-Module
to get it to tell you which assembly can't be loaded (Get-Error
will be good here)@rjmholt : the loading error is clearly shown on the third message from the top. The conflicting module is FusionLog. I guess the conflicting modules are loaded by the VSCode intellisense.
I will work on activating the diagnostic logs extension so I can provide you more details.
the loading error is clearly shown on the third message from the top
That's only part of the error I'm afraid. Try Get-Error
.
The conflicting module is FusionLog
Actually that's not a module. You can see there's no such module given in gmo -List
. Fusion logs are a tool in Windows for viewing .NET Framework assembly binding issues. Given that you're running PS 7, which is on .NET Core 3.1, I don't think they'll help here.
It looks like removing the obsolete Azure repos extension solved the issue but I will continue to investigate
This issue is being closed as inactive, if this issue is still occurring it will be re-opened
If I run with extension enabled this code (and a lot of others Az commands):
Connect-AzAccount
I receive the following error:Connect-AzAccount: The 'Connect-AzAccount' command was found in the module 'Az.Accounts', but the module could not be loaded. For more information, run 'Import-Module Az.Accounts'.
Running the same code without the extension works perfectly. I guess this extension reference some .NET libraries that goes in conflict with the .NET libraries used in Az.Accounts module
Here the modules i have installed: