Skip to content

Commit ba2a2f2

Browse files
committed
Avoid exception when $ExecutionContext is $null
1 parent a80c1a6 commit ba2a2f2

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

PSReadLine/ReadLine.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ private static ConsoleKeyInfo ReadKey()
150150
handleId = WaitHandle.WaitAny(_singleton._requestKeyWaitHandles, 300);
151151
if (handleId != WaitHandle.WaitTimeout)
152152
break;
153+
if (_singleton._engineIntrinsics == null)
154+
continue;
153155

154156
// If we timed out, check for event subscribers (which is just
155157
// a hint that there might be an event waiting to be processed.)
@@ -581,10 +583,13 @@ private void DelayedOneTimeInitialize()
581583
// specifies a custom history save file, we don't want to try reading
582584
// from the default one.
583585

584-
var historyCountVar = _engineIntrinsics.SessionState.PSVariable.Get("MaximumHistoryCount");
585-
if (historyCountVar != null && historyCountVar.Value is int)
586+
if (_engineIntrinsics != null)
586587
{
587-
_options.MaximumHistoryCount = (int)historyCountVar.Value;
588+
var historyCountVar = _engineIntrinsics.SessionState.PSVariable.Get("MaximumHistoryCount");
589+
if (historyCountVar != null && historyCountVar.Value is int)
590+
{
591+
_options.MaximumHistoryCount = (int)historyCountVar.Value;
592+
}
588593
}
589594

590595
_historyFileMutex = new Mutex(false, GetHistorySaveFileMutexName());

0 commit comments

Comments
 (0)