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

ERROR: Could not load file or assembly 'Microsoft.Identity.Client' (ExchangeOnlineManagement + PS 7.2.6) #4178

Closed
6 tasks done
robertcaretta opened this issue Sep 21, 2022 · 14 comments
Labels
Bug: PowerShell 5.1 Bugs when using PowerShell 5.1. Issue-Bug A bug to squash. Resolution-Duplicate Will close automatically.

Comments

@robertcaretta
Copy link

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

When using this extension I get the error below. However if I run the same commands in a regular powershell 7.2 window (not VS Code) the code below runs fine.


ERROR:
OperationStopped: Could not load file or assembly 'Microsoft.Identity.Client, Version=4.41.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxx'.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.2.6
PSEdition                      Core
GitCommitId                    7.2.6
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}       
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visual Studio Code Version

1.71.2
74b1f979648cc44d385a2286793c226e611f59e7
x64

Extension Version

Steps to Reproduce

Could you please test out this combination of tools?

  1. VS Code 1.71.2
  2. PowerShell Extension v2022.8.5
  3. Powershell 7.2.6
  4. ExchangeOnlineManagement 3.0.0

Then try running these commands:
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -InlineCredential
Connect-ExchangeOnline -CertificateThumbprint 'YOURTHUMB' -AppID 'YOURAPP' -Organization 'YOURORG'


ERROR:
OperationStopped: Could not load file or assembly 'Microsoft.Identity.Client, Version=4.41.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxx'.

Visuals

No response

Logs

No response

@robertcaretta robertcaretta added the Issue-Bug A bug to squash. label Sep 21, 2022
@ghost ghost added the Needs: Triage Maintainer attention needed! label Sep 21, 2022
@robertcaretta robertcaretta changed the title ERROR: Powershell Extension + ExchangeOnlineManagement + PS 7.2.6 ERROR: Could not load file or assembly 'Microsoft.Identity.Client' (ExchangeOnlineManagement + PS 7.2.6) Sep 21, 2022
@mhokanson
Copy link

Bump

@Paxxi
Copy link

Paxxi commented Sep 30, 2022

I ran into this as well yesterday and today I ran into it in a plain powershell terminal window as well.

In my case you cannot run Connect-ExchangeOnline after you have imported the MicrosoftTeams module, if you run it before importing the teams module everything works fine.

@andyleejordan
Copy link
Member

@robertcaretta does @Paxxi's findings explain your original issue?

@andyleejordan andyleejordan added Needs: Author Feedback Please give us the requested feedback! and removed Needs: Triage Maintainer attention needed! labels Sep 30, 2022
@robertcaretta
Copy link
Author

I don't recall testing this with Teams. To be honest, I run into all kinds of oddities with modules that still seem to require 5.1.
I guess my question would be has anyone else been able to reproduce the issue with just the items I listed?

@ghost ghost added Needs: Maintainer Attention Maintainer attention needed! and removed Needs: Author Feedback Please give us the requested feedback! labels Sep 30, 2022
@andyleejordan
Copy link
Member

Yeah, unfortunately PowerShell 5.1 is restricted to using the GAC (Global Assembly Cache) on Windows, which is an old-fashioned way of loading DLLs and causes loads of issues, since only one DLL of a name can be in the cache at a time. So modules can real easily have dependency collisions. PowerShell 7 uses an ALC (Assembly Load Context) that allows modules (such as PowerShell Editor Services, etc.) to isolate their dependencies from other modules.

@seanboltman
Copy link

seanboltman commented Oct 1, 2022

I ran into this as well yesterday and today I ran into it in a plain powershell terminal window as well.

In my case you cannot run Connect-ExchangeOnline after you have imported the MicrosoftTeams module, if you run it before importing the teams module everything works fine.

So I am getting this error as well, but I DO NOT have MicrosoftTeams module installed. Get-InstalledModule reports:
3.0.0 ExchangeOnlineManagement and 1.11.0 PnP.PowerShell. Nothing else is installed. Running Powershell 7.2.6. This env was set up against latest VCCode yesterday.

I get the same exact error as the poster on this line of code:

Connect-ExchangeOnline -UserPrincipalName [email protected] -Credential $cred

OperationStopped: Could not load file or assembly 'Microsoft.Identity.Client, Version=4.41.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'.

Same exact code was functioning fine in Powershell 5.1. which also has earlier version of ExchangeOnline powershell module 1.0.1.

So knowing I only have Powershell 7.2.6, ExchangeOnlineManagement 3.0.0, and PnP.PowerShell 1.11.0, what is the issue with this error?

PS: I have to use Powershell 7. If I could stay on 5.1 I would.

@andyleejordan
Copy link
Member

Yeah, unfortunately PnP.PowerShell also causes issues for PowerShell 5.1, #3510.

@andyleejordan andyleejordan added Needs: Author Feedback Please give us the requested feedback! Bug: PowerShell 5.1 Bugs when using PowerShell 5.1. and removed Needs: Maintainer Attention Maintainer attention needed! labels Oct 18, 2022
@ghost ghost closed this as completed Oct 26, 2022
@ghost
Copy link

ghost commented Oct 26, 2022

This issue was closed automatically as author feedback was indicated as needed, but there has been no activity in over a week. Please feel free to reopen with any available information!

@ghost
Copy link

ghost commented Jan 13, 2023

Thank you for your comment, but please note that this issue has been closed for over a week. For better visibility, consider opening a new issue with a link to this instead.

@robertcaretta
Copy link
Author

robertcaretta commented Jun 1, 2023

I'm still having issues with this using VS Code and PS 7.3. Seems like when both ExchangeOnlineManagement and PnP powershell modules are loaded there is a conflict of some kind which prevents Connect-ExchangeOnline from working correctly.

@ghost ghost added Needs: Maintainer Attention Maintainer attention needed! and removed Needs: Author Feedback Please give us the requested feedback! labels Jun 1, 2023
@ghost ghost reopened this Jun 1, 2023
@andyleejordan
Copy link
Member

That sounds likely, the authors of those modules unfortunately need to implement proper AssemblyLoadContext classes and resolvers to isolate their dependencies from each other. From the last time I looked, at least one of those modules had a bug that was isolating only a single dependency.

@andyleejordan
Copy link
Member

andyleejordan commented Jun 8, 2023

Found it: #3510

The AssemblyLoadContext as implemented in PnP.PowerShell is only isolating Microsoft.ApplicationInsights, and PnP.PowerShell has a lot more dependencies (namely Microsoft.Identity.Client) that conflict and need to be isolated in the same manner.

@andyleejordan andyleejordan added Resolution-Duplicate Will close automatically. and removed Needs: Maintainer Attention Maintainer attention needed! labels Jun 8, 2023
@ghost
Copy link

ghost commented Jun 9, 2023

This issue has been marked as duplicate and has not had any activity in a day. It has been closed for housekeeping purposes.

@ghost ghost closed this as completed Jun 9, 2023
@Stuipidsw3ltrd
Copy link

I ran into this as well yesterday and today I ran into it in a plain powershell terminal window as well.

In my case you cannot run Connect-ExchangeOnline after you have imported the MicrosoftTeams module, if you run it before importing the teams module everything works fine.

Paxxi's answer saves my day

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: PowerShell 5.1 Bugs when using PowerShell 5.1. Issue-Bug A bug to squash. Resolution-Duplicate Will close automatically.
Projects
None yet
Development

No branches or pull requests

6 participants