Two Microsoft modules entered the same runspace. Only one leaves with intact assemblies after the load-context collision, because the first assembly that claims a strong name keeps that slot for the life of the PowerShell process.

Graph PowerShell SDK 2.42 is another release aimed at familiar old wounds for Microsoft 365 scripters. I just placed ExchangeOnlineManagement and Microsoft.Graph.Authentication in one PowerShell 7 session, and the next cmdlet call throws FileLoadException or MissingMethodException while pointing at a DLL I do not remember installing. This week's r/PowerShell thread marks the third pass at the same underlying issue.

Why the collision happens at the .NET layer

PowerShell 7 puts every module in the standard AssemblyLoadContext. Strong-named assemblies resolve by simple name alone and only once, so the first version that claims a strong name controls that binding for every later request in the same process. Once the module grabbing Microsoft.IdentityModel.Abstractions saves the slot first, later callers that want a different version get an already loaded copy or a hard failure.

Each module carries its own MSAL and IdentityModel dependency chain: Microsoft.Identity.Client, Microsoft.IdentityModel.JsonWebTokens, Microsoft.IdentityModel.Tokens, Microsoft.IdentityModel.Logging, Microsoft.IdentityModel.Abstractions, and System.IdentityModel.Tokens.Jwt. Graph SDK 2.42 moves this chain forward. Exchange Online PowerShell V3, by contrast, fixed an older set for REST-based cmdlets and Web Account Manager brokering on Windows, which leaves the two dependency graphs on different version tracks.

Neither manifest swaps versions. Even after Remove-Module unloads a module, the assemblies stay in the process, so the broken binding survives until that process exits.

Reproduce the failure in four commands

Know what you typed before you blame the script. The exact version combination matters far more than the wording of the error message, because the message only reports which binding failed first.

Get-Module -ListAvailable Microsoft.Graph.Authentication, ExchangeOnlineManagement |
 Select-Object Name, Version, Path | Format-Table -AutoSize
  1. Open a fresh pwsh window. A recycled session from earlier testing will lie to you.
  2. Import Exchange Online first, then authenticate.
  3. Import the Graph authentication module and connect.
  4. Call any EXO cmdlet and watch the binding break.
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -UserPrincipalName admin@contoso.com -ShowBanner:$false

Import-Module Microsoft.Graph.Authentication
Connect-MgGraph -Scopes "User.Read.All"

Get-EXOMailbox -ResultSize 1

The most common output is Could not load file or assembly 'Microsoft.IdentityModel.Abstractions, Version=8.0.0.0' or Method not found, and it appears above Connect-ExchangeOnline. Reverse the import order, and the error moves to the Graph side. That is the tell.

The isolation pattern that actually holds

Do not merge these modules. Unless Microsoft ships a common dependency baseline, the pairing cannot work from the start, and no such baseline has any shape or form today. Isolate them instead.

One catch comes first: Start-ThreadJob will not solve this. Thread jobs run inside the same process and load context, so the assembly stays shared no matter how clean the job script looks. Use a real child process.

  1. Keep Graph work in the parent session. Import only Microsoft.Graph.Authentication, never the full Microsoft.Graph meta-module.
  2. Push Exchange work into a Start-Job child process or a separate pwsh -NoProfile -File invocation.
  3. Pass credentials explicitly. Child processes do not inherit your interactive token cache, so use a certificate or -Device for the EXO connection.
  4. Return serialized objects across the boundary and format in the parent.
$payload = {
 param($Upn)
 Import-Module ExchangeOnlineManagement -RequiredVersion 3.7.1
 Connect-ExchangeOnline -UserPrincipalName $Upn -ShowBanner:$false
 Get-EXOMailbox -ResultSize 10 |
 Select-Object DisplayName, PrimarySmtpAddress, RecipientTypeDetails
}

$exo = Start-Job -ScriptBlock $payload -ArgumentList "admin@contoso.com"
$exo | Wait-Job -Timeout 300 | Receive-Job
Remove-Job $exo -Force

The parent process never loads the Exchange assembly, and the child process never touches the Graph assembly, so each side keeps a clean load context. The runbook no longer crashes at random on Tuesdays.

Shrink the Graph surface instead

Many scripts import the whole Graph SDK for three endpoints. That is waste. Microsoft.Graph.Authentication and Invoke-MgGraphRequest cover most user, group, and device automation with a much smaller assembly footprint.

Import-Module Microsoft.Graph.Authentication
Connect-MgGraph -Scopes "User.Read.All","Group.Read.All" -NoWelcome

$users = Invoke-MgGraphRequest -Method GET `
 -Uri 'https://graph.microsoft.com/v1.0/users?$top=25'
$users.value | Select-Object displayName, userPrincipalName

This also skips the cmdlet generation layer. Most versioning problems that shift quickly between SDK releases cluster around that layer, which makes the smaller request path easier to keep stable.

← Scroll horizontally on small screens →
ApproachAssembly conflict riskAuth modelCmdlet coverageBest fit
Single session, both modulesHigh, order dependentTwo interactive prompts, WAM broker contentionFull Graph plus full EXOOne-off checks on a clean machine
Child process per moduleNoneSeparate prompts or app-only certificateFullScheduled runbooks, CI jobs
Graph REST onlyLowSingle Graph tokenGraph-covered workloads onlyUser, group, and device automation
EXO REST via Invoke-RestMethodLowEXO token, manual header handlingAdmin API subsetMailbox and transport tasks

High-utility tip: set $PSModuleAutoLoadingPreference = 'None' at the top of every production script. Implicit module loading is the quiet mechanism that drags the Graph SDK into a session meant only for Exchange, and it hides the choice from anyone reading the script. With autoloading off, every Import-Module becomes an explicit, auditable decision, and the conflict surfaces at line 4 instead of line 400.

Prevention checklist for the next SDK bump

  • Pin versions with Import-Module -FullyQualifiedName @{ModuleName='ExchangeOnlineManagement'; RequiredVersion='3.7.1'} instead of floating to latest.
  • Install only the Graph submodules you call. The meta-module pulls every service namespace and multiplies the surface area.
  • Add a Get-Module -ListAvailable audit to your pipeline so a version drift fails the build, not the runbook.
  • Never reuse a long-lived host process for mixed Graph and Exchange work. Restart the host or fork a child.
  • Test the upgrade on a throwaway tenant before touching production automation.

This method is already fixed. Microsoft ships two modules and pushes their dependency graphs together, yet PowerShell still hands out only one assembly slot for each strong name. Process isolation is the only contract that survives the next version.

For the full discussion from other administrators and a wider set of workarounds, follow this link to the original thread: Reddit - r/PowerShell.