microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.5k stars 2.61k forks source link

[BUG]: "Assembly with same name is already loaded" Az.Accounts in Azure PowerShell v. 5.221.102 #18344

Open ArunasFalcon opened 1 year ago

ArunasFalcon commented 1 year ago

Task name

Azure PowerShell

Task version

5.221.102

Environment type (Please select at least one enviroment where you face this issue)

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

No response

Operation system

Windows

Task log

2023-05-23T14:37:17.2033551Z ##[section]Starting: Deploy Logic apps
2023-05-23T14:37:17.2141091Z ==============================================================================
2023-05-23T14:37:17.2141218Z Task         : Azure PowerShell
2023-05-23T14:37:17.2141296Z Description  : Run a PowerShell script within an Azure environment
2023-05-23T14:37:17.2141385Z Version      : 5.221.102
2023-05-23T14:37:17.2141443Z Author       : Microsoft Corporation
2023-05-23T14:37:17.2141507Z Help         : https://aka.ms/azurepowershelltroubleshooting
2023-05-23T14:37:17.2141599Z ==============================================================================
2023-05-23T14:37:18.1871546Z Generating script.
2023-05-23T14:37:18.2274421Z ========================== Starting Command Output ===========================
2023-05-23T14:37:18.2476205Z ##[command]"C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\4ed5cd8c-1a38-4a38-98aa-750219a2e3b8.ps1'"
2023-05-23T14:37:21.5092428Z Added TLS 1.2 in session.
2023-05-23T14:37:22.6151361Z ##[command]Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
2023-05-23T14:37:26.0338613Z ##[command]Clear-AzContext -Scope Process
2023-05-23T14:37:26.1170802Z ##[command]Connect-AzAccount System.Collections.Hashtable
2023-05-23T14:37:27.0246826Z 
2023-05-23T14:37:27.0580529Z VERBOSE: Command [Connect-AzAccount] succeeded.
2023-05-23T14:37:27.0606884Z ##[command]Set-AzContext System.Collections.Hashtable
2023-05-23T14:37:27.4290114Z Account                              SubscriptionName TenantId                             Environment
2023-05-23T14:37:27.4290645Z -------                              ---------------- --------                             -----------
2023-05-23T14:37:27.4291828Z *** <removed>      <removed> AzureCloud
2023-05-23T14:37:27.4291945Z 
2023-05-23T14:37:27.4293842Z Name               : <removed> (<removed>) - <removed> - 
2023-05-23T14:37:27.4294240Z                      ***
2023-05-23T14:37:27.4294815Z Account            : ***
2023-05-23T14:37:27.4295441Z Environment        : AzureCloud
2023-05-23T14:37:27.4295723Z Subscription       : <removed>
2023-05-23T14:37:27.4295989Z Tenant             : <removed>
2023-05-23T14:37:27.4296245Z TokenCache         : 
2023-05-23T14:37:27.4296829Z VersionProfile     : 
2023-05-23T14:37:27.4297127Z ExtendedProperties : {}
2023-05-23T14:37:27.4297290Z 
2023-05-23T14:37:27.4524925Z VERBOSE: Command [Set-AzContext] succeeded.
2023-05-23T14:37:27.4973374Z ##[command]Import-Module -Name C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.12.3\Az.Accounts.psd1 -Global
2023-05-23T14:37:28.4322258Z ##[error]Assembly with same name is already loaded
2023-05-23T14:37:28.4329562Z ##[error]PowerShell exited with code '1'.
2023-05-23T14:37:28.4330463Z Added TLS 1.2 in session.
2023-05-23T14:37:29.6180521Z ##[command]Disconnect-AzAccount -Scope Process -ErrorAction Stop
2023-05-23T14:37:29.8244526Z ##[command]Clear-AzContext -Scope Process -ErrorAction Stop
2023-05-23T14:37:29.9944326Z ##[section]Finishing: Deploy Logic apps

Relevant log output

2023-05-23T14:37:27.4973374Z ##[command]Import-Module -Name C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.12.3\Az.Accounts.psd1 -Global
2023-05-23T14:37:28.4322258Z ##[error]Assembly with same name is already loaded
2023-05-23T14:37:28.4329562Z ##[error]PowerShell exited with code '1'.

Aditional info

Task ran correctly in the version 5.220.0.

For comparison purposes, here is the output of the same task running correctly 4 days ago using the old version:

2023-05-23T04:00:45.2952817Z ##[section]Starting: Deploy Logic apps
2023-05-23T04:00:45.3068166Z ==============================================================================
2023-05-23T04:00:45.3068471Z Task         : Azure PowerShell
2023-05-23T04:00:45.3068542Z Description  : Run a PowerShell script within an Azure environment
2023-05-23T04:00:45.3068634Z Version      : 5.220.0
2023-05-23T04:00:45.3068712Z Author       : Microsoft Corporation
2023-05-23T04:00:45.3068798Z Help         : https://aka.ms/azurepowershelltroubleshooting
2023-05-23T04:00:45.3068891Z ==============================================================================
2023-05-23T04:00:46.3045389Z Generating script.
2023-05-23T04:00:46.3452274Z ========================== Starting Command Output ===========================
2023-05-23T04:00:46.3681515Z ##[command]"C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\6879e41f-3ce0-41bc-a7a6-2129a4580b40.ps1'"
2023-05-23T04:00:49.6859394Z Added TLS 1.2 in session.
2023-05-23T04:00:50.3687582Z ##[command]Import-Module -Name C:\Modules\az_9.3.0\Az.Accounts\2.12.2\Az.Accounts.psd1 -Global
2023-05-23T04:00:54.0419112Z ##[command]Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
2023-05-23T04:00:55.3735612Z ##[command]Clear-AzContext -Scope Process
2023-05-23T04:00:56.3742335Z ##[command]Connect-AzAccount System.Collections.Hashtable
2023-05-23T04:00:56.3742519Z 
2023-05-23T04:00:56.3742794Z VERBOSE: Command [Connect-AzAccount] succeeded.
2023-05-23T04:00:56.3743034Z ##[command]Set-AzContext System.Collections.Hashtable
2023-05-23T04:00:56.8351639Z Account                              SubscriptionName TenantId                             Environment
2023-05-23T04:00:56.8353391Z -------                              ---------------- --------                             -----------
2023-05-23T04:00:56.8354708Z *** <removed>      <removed> AzureCloud
2023-05-23T04:00:56.8354937Z 
2023-05-23T04:00:56.8355637Z Name               : <removed> (<removed>) - <removed> - 
2023-05-23T04:00:56.8356022Z                      ***
2023-05-23T04:00:56.8356504Z Account            : ***
2023-05-23T04:00:56.8356735Z Environment        : AzureCloud
2023-05-23T04:00:56.8357215Z Subscription       : <removed>
2023-05-23T04:00:56.8357568Z Tenant             : <removed>
2023-05-23T04:00:56.8357841Z TokenCache         : 
2023-05-23T04:00:56.8358095Z VersionProfile     : 
2023-05-23T04:00:56.8362276Z ExtendedProperties : {}
2023-05-23T04:00:56.8362582Z 
2023-05-23T04:00:56.8623462Z VERBOSE: Command [Set-AzContext] succeeded.
<user script output begins here as expected>
ArunasFalcon commented 1 year ago

Workaround: Switching to task version 4.*

jamesbr-ashn commented 1 year ago

I experienced the same issue. As @ArunasFalcon mentioned, setting to AzurePowerShell@4 resolved the issue. We are using self-hosted agents. Current agent version: '2.175.2'

UPDATE: Experiencing the same problem after agent update. Current agent version: '3.220.2'

crownmike commented 1 year ago

We're also receiving this error on multiple VMSS self-hosted build agents and using the workaround switching from AzurePowerShell@5 to AzurePowerShell@4 has got us back up and running.

##[debug]Error record:
##[debug]
##[debug]Import-Module: C:\a\_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\5.221.102\ps_modules\VstsAzureHelpers_\InitializeAzModuleFunctions.ps1:65
##[debug]Line |
##[debug]  65 |  …   $module = Import-Module -Name $module.Path -Global -PassThru -Force …
##[debug]     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##[debug]     | Assembly with same name is already loaded
##[debug]
##[debug]Script stack trace:
##[debug]at Import-AzModule, C:\a\_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\5.221.102\ps_modules\VstsAzureHelpers_\InitializeAzModuleFunctions.ps1: line 65
##[debug]at Initialize-AzModule, C:\a\_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\5.221.102\ps_modules\VstsAzureHelpers_\InitializeAzModuleFunctions.ps1: line 24
##[debug]at <ScriptBlock>, C:\a\_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\5.221.102\CoreAz.ps1: line 27
##[debug]at <ScriptBlock>, C:\a\_temp\a4626e70-1b4a-4d8f-bad2-2652afcbf8d9.ps1: line 3
##[debug]at <ScriptBlock>, <No file>: line 1
##[debug]Exception:
##[debug]System.IO.FileLoadException: Assembly with same name is already loaded
##[debug]   at System.Management.Automation.Runspaces.InitialSessionState.Bind_LoadAssemblies(ExecutionContext context)
##[debug]   at System.Management.Automation.Runspaces.InitialSessionState.Bind(ExecutionContext context, Boolean updateOnly, PSModuleInfo module, Boolean noClobber, Boolean local, Boolean setLocation)
##[debug]   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)
##[error]Assembly with same name is already loaded
##[debug]Processed: ##vso[task.logissue type=error]Assembly with same name is already loaded
##[debug]Exit code: 1
##[debug]Leaving Invoke-VstsTool.
##[error]PowerShell exited with code '1'.
srbrills commented 1 year ago

Also viewing this issue with AzureCLI task version 2.*. Switching to AzurePowerShell task, either version 4 or 5, did not resolve the issue. Self-hosted agent version is 3.220.5. All logic runs fine locally. Switching to a hosted agent works, however.

github-actions[bot] commented 9 months ago

This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

srbrills commented 9 months ago

This is still an issue with task version 5.*.

github-actions[bot] commented 3 months ago

This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

srbrills commented 3 months ago

This is still an issue with task version 5.*.