Can’t use ExchangeOnlineManagement V3.1.0 together with Microsoft.Graph.Authentication V1.27.0 in powershell

Vincent Bok 30 Reputation points
2023-05-26T13:47:37.0666667+00:00

Can’t use ExchangeOnlineManagement V3.1.0 together with Microsoft.Graph.Authentication V1.27.0 in powershell

I’m having some trouble with using the ExchangeOnlineManagement V3.1.0 together with Microsoft.Graph.Authentication V1.27.0 in powershell. Both modules work perfectly independent from eachother, but when I want to use them both in the same script, the following error occurs:
“Could not load file or assembly 'System.IdentityModel.Tokens.Jwt, Version=6.22.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (0x80131621)”.

The exception occurs when I try to use the following cmdlet from the ExchangeOnlineManagement v3.1.0 module:

” Connect-ExchangeOnline -Organization $VerifiedDefaultDomain -AppId $AppId -Certificate $CertObject”

As you can see, I am using app only authentication using certificates. This command does work with the 2.0.5 version of ExchangeOnlineManagement in combination with Microsoft.graph.authentication, but as soon as I try to use the 3.1.0 version of the  ExchangeOnlineManagement, it stops working.

I think there is an version conflict between the two assemblies, because when the error occurs, and I run this command:
“[System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object Location | Sort-Object -Property FullName | Select-Object -Property FullName, Location, GlobalAssemblyCache, IsFullyTrusted | Out-GridView”
then I can see that the version of 'System.IdentityModel.Tokens.Jwt that is actually used, is 5.6.0.0 but the ExchangeOnlineManagement 3.1.0 module requires 6.22.1.0.

So what do we have now? We have 2 modules that both require different versions of the same code assembly in order for certificate authentication to work.

ExchangeOnlineManagement V3.1.0 = System.IdentityModel.Tokens.Jwt V6.22.1.0

Microsoft.Graph V.1.27.0 = System.IdentityModel.Tokens.Jwt V5.6.0.0

Ofcourse you can’t use both assemblies in the same environment, because the runtime wouldn’t know which one to use when. I think this is something that Microsoft should fix in their Microsoft.Graph.Authentication module. I believe they should update the System.IdentityModel.Tokens.Jwt assembly in their module.

Can someone tell me how to fix this, or can Microsoft acknowledge this issue and confirm that they are working on it? Feel free to contact me!

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,582 questions
Exchange Server Development
Exchange Server Development
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Development: The process of researching, productizing, and refining new or existing technologies.
508 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,052 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Vasil Michev 95,181 Reputation points MVP
    2023-05-26T16:13:31.0633333+00:00

    Best open an issue over at Github for the Graph module (the Exchange module one is not open-sourced): https://github.com/microsoftgraph/msgraph-sdk-powershell/issues


  2. Matt Hamilton 26 Reputation points
    2023-06-14T06:06:23.7333333+00:00

    I've just struck the same issue. The comments from the Graph team on Vincent's issue indicate that the ExchangeOnlineManagment module needs to isolate its dependencies into an Assembly Loading Context to prevent this issue.

    How do we log an issue with the EXO module team?

    0 comments No comments