Fix PnP ALC initializer with loaded assemblies - #5481
Merged
gautamdsheth merged 1 commit intoOct 2, 2026
Merged
Conversation
Collaborator
|
Thanks @FabienTschanz , merged it !! |
Contributor
Author
|
Thank you, will check it out tomorrow! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type
Related Issues?
What is in this Pull Request ?
Fixes the PowerShell process crash (stack overflow) in
Connect-PnPOnlinewhen another module, such as MicrosoftTeams or ExchangeOnlineManagement, has already loaded an olderMicrosoft.Identity.Clientinto the default AssemblyLoadContext. This is a regression from #5393 (3.4.0).PnPAssemblyLoadContext.Loaddeferred a boundary assembly (Microsoft.Identity.Client*,System.Text.Json) to the default context whenever the default context held an assembly with that name, regardless of its version. When that copy is older than the one PnP references, the loop goes like this:Resolving.ResolveDependencyroutes the request to the private context.Resolvingagain.This repeats until the stack overflows.
Changes:
PnPAssemblyLoadContext.DefersToDefaultContextreplacesIsLoadedInDefaultContext. A boundary assembly defers only when the default context holds a copy that PnP does not ship, or one at least the version PnP ships.Microsoft.Identity.Client.*assemblies defer only whenMicrosoft.Identity.Clientitself defers, so the private context never pairs its own MSAL with a host copy of an MSAL extension.ResolveDependencyroutesPnP.PowerShell.dll's reference to that copy as well.ResolveDependencyno longer routes a deferred boundary assembly into the private context, which is what closed the loop. It returns, in this order:null.How this was tested
I tested this with both PowerShell 7.6.6 (.NET 10) and with 7.4.20 (.NET 8) with the same results.
Note: "Connect" means
Connect-PnPOnlinewith a throw-away certificate against a tenant that doesn't exist. ReachingAADSTS90002means MSAL ran.devImport-Module PnP.PowerShellFileNotFoundExceptionfor that loadConnect-PnPOnlinein 6ForEach-Object -ParallelrunspacesTested against a tenant with app-only certificate authentication, in three orders:
Connect-MicrosoftTeams, thenConnect-PnPOnlineConnect-ExchangeOnline, thenConnect-PnPOnlineAll three connect, and
Get-PnPTenant,Get-CsTenantandGet-OrganizationConfigkeep working afterwards. The released 3.4.1 and unpatcheddevcrash in the first two orders.