question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

#Requires -Modules causes error "Import-Module: Assembly with same name is already loaded"

See original GitHub issue

Steps 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:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

4reactions
JeremyTBradshawcommented, Sep 8, 2020

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

1reaction
iSazonovcommented, Sep 4, 2020

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

<div> GitHub</div><div>microsoft/Partner-Center-PowerShell</div><div>PowerShell module for managing Partner Center resources. - microsoft/Partner-Center-PowerShell</div>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error of Assembly with same name is already loaded doing ...
Try to import ( Import-Module ) the modules in a certain fixed order, to make sure the more recent assembly versions are loaded...
Read more >
Azure Automation PowerShell Error "Assembly with same ...
The error message "Assembly with same name is already loaded" occurs when you try to import a module in Azure Automation that has...
Read more >
Resolving PowerShell Module Conflicts | How
Import -Module: Assembly with same name is already loaded. The exact error message and scenario of the conflict depends on which version of ......
Read more >
How to actually uninstall conflicting PowerShell modules?
This article explains how to resolve “Import-Module: Assembly with same name is already loaded” error in PowerShell (and a couple of related issues...
Read more >
Azure Function App fails with: “ERROR: Assembly with ...
Azure Function App fails with: “ERROR: Assembly with same name is already loaded”. I was recently notified by a colleague that the Azure ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found