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.

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

See original GitHub issue

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

ms-vscode.powershell@2022.8.5

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
seanboltmancommented, 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 sp_admin@geoengineers.com -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.

1reaction
Paxxicommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting 'Could not load file or assembly 'Microsoft.Identity ...
I am trying to run a script in Powershell 7 using PnP.PowerShell version 1.5.0 and I am getting error: Could not load file...
Read more >
Could not load file or assembly Microsoft.Identity.Client
This error message can appear if PowerShell has been locked down with a PSLockDownPolicy. If PSLockdownPolicy has set the ExecutionContext SessionState ...
Read more >
Issue with Connect-ExchangeOnline in script : r/PowerShell
... this error when attempting to run Connect-ExchangeOnline. New-ExoPSSession: Could not load file or assembly 'Microsoft.Identity.Client ...
Read more >
ERROR: Could not load file or assembly 'Microsoft.Identity.Client
Seems like function app is not registered to use Managed Identity. Managed Identity makes the function app authenticate to Azure resources.
Read more >
Install Exchange Online PowerShell V2 - ALI TAJRAN
How to install Exchange Online PowerShell V2 module and connect to ... If you get an error that it's unable to install, read...
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