Skip to content

Commit 1b03005

Browse files
authored
Never load a module targeting the PSReadLine module's SessionState (PowerShell#24909)
1 parent 4d174fc commit 1b03005

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs

+6-11
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,12 @@ protected internal struct ImportModuleOptions
136136

137137
internal SessionState TargetSessionState
138138
{
139-
get
140-
{
141-
if (BaseGlobal)
142-
{
143-
return this.Context.TopLevelSessionState.PublicSessionState;
144-
}
145-
else
146-
{
147-
return this.Context.SessionState;
148-
}
149-
}
139+
// Module loading could happen during tab completion triggered by PSReadLine,
140+
// but that doesn't mean the module should be loaded targeting the PSReadLine
141+
// module's session state. In that case, use Global session state instead.
142+
get => BaseGlobal || Context.EngineSessionState.Module?.Name is "PSReadLine"
143+
? Context.TopLevelSessionState.PublicSessionState
144+
: Context.SessionState;
150145
}
151146

152147
/// <summary>

0 commit comments

Comments
 (0)