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; + } + } } ///