Repository navigation
Description
Describe the bug
I am working in a script on PowerShell 5.1 with ExchangeOnlineManagement and Microsoft.Graph.Authentication and if I try to connect to Graph after connect to Exchange Online I received an error message:

In the troubleshooting I found that the issue appear as well just importing the modules in the same order:

In case that I run in verbose mode
Import-Module ExchangeOnlineManagement -Verbose
Import-Module Microsoft.Graph.Authentication -Verbose

It looks it is trying to look for Azure.Core on ExchangeOnlineManagement module.
if I change the order all works fine:

Expected behavior
Be able to work with both modules, without errors and could use any order in the request.
How to reproduce
Connect-ExchangeOnline -ShowBanner:$false
Connect-MgGraph -NoWelcome
Import-Module ExchangeOnlineManagement
Import-Module Microsoft.Graph.Authentication
Import-Module ExchangeOnlineManagement -Verbose
Import-Module Microsoft.Graph.Authentication -Verbose
SDK Version
2.19.0
Latest version known to work for scenario above?
No response
Known Workarounds
It works with PowerShell 7 or with ExchangeOnlineManagement 3.4.0
Debug output
Click to expand log
```VERBOSE: Cannot verify the Microsoft .NET Framework version 4.7.2 because it is not included in the list of permitted versions.
VERBOSE: Loading 'FormatsToProcess' from path 'C:\Users\xxxxx\WindowsPowerShell\Modules\Microsoft.Graph.Authentication\2.19.0\Microsoft.Graph.Authentication.format.ps1xml'.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.Graph.Authentication.
VERBOSE: Loading module from path 'C:\Users\xxxxx\WindowsPowerShell\Modules\Microsoft.Graph.Authentication\2.19.0\Microsoft.Graph.Authentication.dll'.
VERBOSE: Importing cmdlet 'Get-ModuleCmdlet'.
VERBOSE: Importing cmdlet 'Get-ScriptCmdlet'.
VERBOSE: Importing cmdlet 'Connect-MgGraph'.
VERBOSE: Importing cmdlet 'Disconnect-MgGraph'.
VERBOSE: Importing cmdlet 'Add-MgEnvironment'.
VERBOSE: Importing cmdlet 'Get-MgEnvironment'.
VERBOSE: Importing cmdlet 'Remove-MgEnvironment'.
VERBOSE: Importing cmdlet 'Set-MgEnvironment'.
VERBOSE: Importing cmdlet 'Get-MgContext'.
VERBOSE: Importing cmdlet 'Get-MgGraphOption'.
VERBOSE: Importing cmdlet 'Invoke-MgGraphRequest'.
VERBOSE: Importing cmdlet 'Set-MgGraphOption'.
VERBOSE: Importing cmdlet 'Get-MgRequestContext'.
VERBOSE: Importing cmdlet 'Set-MgRequestContext'.
VERBOSE: Importing alias 'Connect-Graph'.
VERBOSE: Importing alias 'Disconnect-Graph'.
VERBOSE: Importing alias 'Disconnect-Graph'.
VERBOSE: Importing alias 'Disconnect-Graph'.
VERBOSE: Importing alias 'Disconnect-Graph'.
VERBOSE: Importing alias 'Disconnect-Graph'.
VERBOSE: Importing alias 'Disconnect-Graph'.
VERBOSE: Importing alias 'Disconnect-Graph'.
VERBOSE: Importing alias 'Invoke-GraphRequest'.
VERBOSE: Importing alias 'Invoke-MgRestMethod'.
VERBOSE: Importing alias 'Invoke-GraphRequest'.
VERBOSE: Importing alias 'Invoke-MgRestMethod'.
VERBOSE: Importing alias 'Invoke-GraphRequest'.
VERBOSE: Importing alias 'Invoke-MgRestMethod'.
VERBOSE: Importing alias 'Invoke-GraphRequest'.
VERBOSE: Importing alias 'Invoke-MgRestMethod'.
VERBOSE: Loading module from path 'C:\Users\xxxxx\WindowsPowerShell\Modules\Microsoft.Graph.Authentication\2.19.0\Microsoft.Graph.Authentication.Core.dll'.
Import-Module : Could not load file or assembly 'file:///C:\Users\xxxxx\WindowsPowerShell\Modules\ExchangeOnlineManagement\3.5.0\netFramework\Azure.Core.dll' or one of its dependencies. The system cannot find the file specified.
At line:1 char:1
- Import-Module Microsoft.Graph.Authentication -Debug
-
+ CategoryInfo : NotSpecified: (:) [Import-Module], FileNotFoundException + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand
</details>
### Configuration
Name Value
---- -----
PSVersion 5.1.22621.3672
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.22621.3672
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Windows 10, 11, Server 2022 x64
### Other information
_No response_


Activity
McDoMaster commentedon Jun 21, 2024
Got the same issue on the version 3.5.0 of Exchange Online Management. The workaround remains the same.
Eulafe commentedon Jul 2, 2024
Got the same issue on Azure Automation with Microsoft.Graph.* v2.19.0 + ExchangeOnlineManagement v3.5.0
Workaround works with Microsoft.Graph.* v2.19.0 + ExchangeOnlineManagement v3.4.0
Thanks for this!
timayabi2020 commentedon Jul 29, 2024
Hi Ignacio Serrano (@iserrano76) please update to the latest Microsoft.Graph PowerShell SDK version (2.21.0) which has the latest

Azure.Coreversion (1.39.0) compatible with ExchangeOnlineManagement version 3.5.1.secretworkpersona commentedon Jul 30, 2024
Latest version (2.21.0) does not resolve the issue for me.
iserrano76 commentedon Jul 30, 2024
Hi Tim (@timayabi2020),
It looks the same issue:

timayabi2020 commentedon Jul 30, 2024
Ignacio Serrano (@iserrano76) apologies I just realized that I was in a PowerShell 7 session and not 5.1 and I was able to reproduce the issue. After investigations, it seems that
ExchangeOnlineManagmentmodule from version 3.5.0 onwards is not isolating its dependencies into an Assembly Loading Context as described here https://learn.microsoft.com/en-us/powershell/scripting/dev-cross-plat/resolving-dependency-conflicts?view=powershell-7.4. Besides the work around of rolling back to version 3.4.0, you might want to consider running the modules in their individual PowerShell sessions.13 remaining items
timayabi2020 commentedon Sep 6, 2024
For those who are still experiencing this issue, try and use the latest preview version of exchange online.
Use this command to install
Install-Module -Name ExchangeOnlineManagement -AllowPrerelease -Forceks-git-22 commentedon Sep 9, 2024
Tim (@timayabi2020)
Thank you for the delightful news.
I had tried ExchangeOnlineManagement 3.6.0.Preview1.
The issue was resolved.
I executed the commands in the order of Connect-MgGraph, Connect-ExchangeOnline, and also in the order of Connect-ExchangeOnline, Connect-MgGraph, and both were successful.
Therefore, I am looking forward to the release of the next official version.
spplante commentedon Sep 9, 2024
Tim (@timayabi2020) I have the same issue with 3.6.0 with the PnP.PowerShell module. If I import import the PnP module before or after importing the exchange module, the Connect-ExchangeOnline or Connect-IPPSSession both fail with the same error.
Downgrading to 3.4.0 does fix the issue in my case, but not upgrading to 3.6.0.
iserrano76 commentedon Sep 10, 2024
The issue is in Powershell 5.1 and Import-module do not offer me AllowPrerelease parameter
How do you install 3.6 Preview in powershell 5.1?
spplante commentedon Sep 10, 2024
Ignacio Serrano (@iserrano76) You need to update PowershellGet in order to have the switch available. I have the exacte same version of PowerShell as you and I do have the "AllowPrerelease" switch
spplante commentedon Sep 10, 2024
I upgraded to PowerShell 7 and used PnP.PowerShell 2.12.0 instead of 1.12.0 and it works fine now with ExchangeOnlineManagement 3.6.0.
iserrano76 commentedon Sep 10, 2024
I test it with PS5.1 and EXO management 3.6.0-Preview1 and looks fine, I can connect both sessions.
Great, Thanks!!
I will wait for final version :)
syne0 commentedon Sep 12, 2024
Confirmed it fixed my issue with importing module that had both exo and graph module dependencies. Thanks!
iyerusad commentedon Nov 21, 2024
Similarly see issues with attempting to run ExchangeOnlineManagement module within Azure Functions.
I am able to successfully
Import-Module ExchangeOnlineManagement@ 3.0.0Running most higher versions doesn't appear to work (e.g.
3.6.0,3.7.0-preview1,3.5.0, etc).Import-Module $RestModulePathdidn't make much since addingTest-Path $RestModulePathseems to confirm the file it is looking for exists.At the moment downgraded to EXO
3.0.0, hoping a fix comes forth.Output from EXO @
3.6.0(as defined in requirements.psd1):ITJoeSchmo commentedon Dec 18, 2024
I thought it was worth hopping on here, I believe this is basically just another instance of Microsoft bundling conflicting versions of the NewtonSoft.Json assembly between modules which end up being loaded together, which ultimately is the same as this issue: Azure/azure-powershell#21960
There have been assembly conflicts now between Az PowerShell submodules <> ExchangeOnline <> Graph submodules <> AzureAutomation HybridWorker modules. One solution is to move to PS Core, which can handle assembly conflicts between modules imported.
For PS5.1 I posted the below work-around and script to implement it in that same thread here: Azure/azure-powershell#21960 (comment)