Never load a module targeting the PSReadLine module's SessionState (#24909)

This commit is contained in:
Dongbo Wang
2025-02-18 10:18:30 -08:00
committed by GitHub
parent 4d174fcbb7
commit 1b03005d1a
@@ -136,17 +136,12 @@ namespace Microsoft.PowerShell.Commands
internal SessionState TargetSessionState
{
get
{
if (BaseGlobal)
{
return this.Context.TopLevelSessionState.PublicSessionState;
}
else
{
return this.Context.SessionState;
}
}
// 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;
}
/// <summary>