#Requires -Modules causes error "Import-Module: Assembly with same name is already loaded"
See original GitHub issueSteps to reproduce
Call a script or function with #Requires -Modules [module info], while having the the required module installed. I’ve only tested with the PartnerCenter module, using either of these in my tests:
#Requires -Modules @{ModuleName='PartnerCenter';ModuleVersion='3.0.10'}, Az.Accounts
or
#Requires -Modules PartnerCenter
Both produce the same error when calling the script.
PS C:\Users\MY-USER> .\Documents\GitHub\PowerShell\Connect-PartnerCenterAsSecureApp.ps1
Import-Module: Assembly with same name is already loaded
The script I’m calling is very basic (https://github.com/JeremyTBradshaw/PowerShell/blob/master/Connect-PartnerCenterAsSecureApp.ps1)
Expected behavior
I expect the script to not fail immediately and instead carry on because I have the module that is required already installed, and it shouldn’t matter if it is already loaded or not. For this example script, I should get prompted for the values of the mandatory properties whereas my example has omitted using any parameters.
PS C:\Users\MY-USER>.\Documents\GitHub\PowerShell\Connect-PartnerCenterAsSecureApp.ps1
cmdlet Connect-PartnerCenterAsSecureApp.ps1 at command pipeline position 1
Supply values for the following parameters:
CSPTenantId:
Actual behavior
PS C:\Users\MY-USER> .\Documents\GitHub\PowerShell\Connect-PartnerCenterAsSecureApp.ps1
Import-Module: Assembly with same name is already loaded
Environment data
Name Value
---- -----
PSVersion 7.0.3
PSEdition Core
GitCommitId 7.0.3
OS Microsoft Windows 10.0.19041
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:7

Top Related StackOverflow Question
@vexx32 and @iSazonov thanks again for you help. I just uninstalled the older 1.5.2 version of Az.Accounts (from the AllUsers scope) and installed the latest into CurrentUser. This immediately solved my problem.
I wish I had caught this before opening the issue, so apologies for the wasted cycles.
I see PartnerCenter depends on NewtonSoft.Json - perhaps Az module too but another version. https://github.com/microsoft/Partner-Center-PowerShell/tree/master/src/lib/NetFxPreloadAssemblies