ExchangeOnlineManagement module error – Could not load file or assembly ‘System.IdentityModel.Tokens.Jwt, Version= …’

Updated the ExchangeOnlineManagement module to the latest 3.0 version on my laptop as well as some of the Azure Functions. And it started throwing the following error:

OperationStopped: Could not load file or assembly ‘System.IdentityModel.Tokens.Jwt, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35’. Could not find or
load a specific file. (0x80131621)

This is with PowerShell 7.2 as that’s what I am using.

On the laptop I noticed I get this error if I load the Graph module and then ExchangeOnlineManagement. My Graph module was on version 1.10.0, so I updated it today but that didn’t help. The error isn’t when I load the ExchangeOnlineManagement module, but when I do the actual connect. I use certificates and this line throws the error:

Ditto with Azure Functions.

Eventually I downgraded to the 2.x latest preview version in Azure Functions; and keep in mind to connect to Exchange Online in a separate session when on my laptop. I’ve similar issues in the past with the Az module too wherein it conflicts with Graph or PnP.PowerShell.

Update: Not sure if it’s relevant but I encountered this problem again and fixed it a different way.