From b80102756098b30f11cff20d47589e5c27252db0 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Tue, 29 Jul 2025 14:32:21 -0700 Subject: [PATCH] Revert "Never load a module targeting the PSReadLine module's `SessionState`" (#25792) The change causes nested modules of PSReadLine to be loaded to global session state as well. It's possible to check if we are currently importing the PSReadLine module but the check would depend on the current design of the PSReadLine module, such as how many nested modules it has, its module type, and etc., which is fragile. It's safer to just revert the change. --- .../engine/Modules/ModuleCmdletBase.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs index f47f9b45e4..f07ddcc633 100644 --- a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs +++ b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs @@ -136,12 +136,17 @@ namespace Microsoft.PowerShell.Commands internal SessionState TargetSessionState { - // Module loading could happen during tab completion triggered by PSReadLine, - // but that doesn't mean the module should be loaded targeting the PSReadLine - // module's session state. In that case, use Global session state instead. - get => BaseGlobal || Context.EngineSessionState.Module?.Name is "PSReadLine" - ? Context.TopLevelSessionState.PublicSessionState - : Context.SessionState; + get + { + if (BaseGlobal) + { + return this.Context.TopLevelSessionState.PublicSessionState; + } + else + { + return this.Context.SessionState; + } + } } ///