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

Assembly with same name is already loaded #1083

Open
alexandair opened this issue Sep 15, 2024 · 8 comments
Open

Assembly with same name is already loaded #1083

alexandair opened this issue Sep 15, 2024 · 8 comments

Comments

@alexandair
Copy link
Collaborator

While I've worked with Entra PowerShell, Visual Studio code has crashed.
After starting a new session, Entra PowerShell command couldn't run. It failed with the "Assembly with same name is already loaded" error. Entra PowerShell command was the first executed in that new session and Get-Module executed after didn't show any Microsoft.Graph module loaded.

Even after the restart of the VM, I couldn't run Entra PowerShell commands.

Explicitly loading the module with Import-Module Microsoft.Graph.Entra doesn't provide any additional details about the problem.

@jkav58
Copy link

jkav58 commented Sep 17, 2024

Even specifying -Prefix fails with the Assembly with same name is already loaded.

@kayasax
Copy link

kayasax commented Sep 18, 2024

I'm also experiencing lot of errors like this
image
Usually opening a new terminal can work, but not always.
I also tried to remove all modules, delete all directories and reinstall, but still facing the issue not being able to understand the problem

@jkersey-amllp
Copy link

Also encountering similar stuff but with Get-MgUser

@SamErde
Copy link
Collaborator

SamErde commented Nov 5, 2024

I suspect this may be a MS Graph SDK issue and not necessarily an Entra PowerShell module issue.

Whatever the cause, there are several closed issues in the Graph SDK PowerShell repo that point to purging the module[s] as a solution.

These aren't as valuable as a real root cause analysis that finds and fixes the actual problem, but I'm curious if it may help address the symptoms described in this issue.

@jkersey-amllp
Copy link

I suspect this may be a MS Graph SDK issue and not necessarily an Entra PowerShell module issue.

Whatever the cause, there are several closed issues in the Graph SDK PowerShell repo that point to purging the module[s] as a solution.

These aren't as valuable as a real root cause analysis that finds and fixes the actual problem, but I'm curious if it may help address the symptoms described in this issue.

Thanks Sam. I was able to resolve my issue loading Microsoft.Graph.Users by upgrading the module.

@AndersRask
Copy link

This is a common issue with PowerShell modules that uses different versions of the same assembly. If you do not address this when designing the module, it will not be usable with other modules, unless you are very careful loading one module before the other to get the newest assembly loaded (often Authentication is the culprit).

The solution is called Assembly Load Contexts Bridging (ALC).
I brought this up in the PnP.PowerShell project, where they implemented it and it solved a lot of these assembly load issues:
pnp/powershell#3207

ALC is the "new" way of loading assemblies in PowerShell 7, and should have better ways of handling multiple versions of the same assembly. There are a few samples in the code below that show how to avoid this breaking code into two modules and using the IModuleAssemblyInitializer to lazy load and undload assemblies into ALC.

https://learn.microsoft.com/en-us/powershell/scripting/dev-cross-plat/resolving-dependency-conflicts?view=powershell-7.3#more-robust-solutions

Since this module is still very young, this would be the perfect time to adapt ALC Bridging pattern to the code!

@SamErde
Copy link
Collaborator

SamErde commented Nov 18, 2024

Thanks for the tip! Is there any functional equivalent that is backwards compatible with Windows PowerShell 5.1?

@SteveMutungi254
Copy link
Contributor

Related issue/solution: #1242

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

No branches or pull requests

8 participants