File tree 1 file changed +13
-2
lines changed
src/PowerShellEditorServices/Services/PowerShell/Host
1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -475,8 +475,19 @@ private void Run()
475
475
( PowerShell pwsh , RunspaceInfo localRunspaceInfo , EngineIntrinsics engineIntrinsics ) = CreateInitialPowerShellSession ( ) ;
476
476
_mainRunspaceEngineIntrinsics = engineIntrinsics ;
477
477
_localComputerName = localRunspaceInfo . SessionDetails . ComputerName ;
478
- _runspaceStack . Push ( new RunspaceFrame ( pwsh . Runspace , localRunspaceInfo ) ) ;
479
- PushPowerShellAndRunLoop ( pwsh , PowerShellFrameType . Normal | PowerShellFrameType . Repl , localRunspaceInfo ) ;
478
+
479
+ // NOTE: In order to support running events registered to PowerShell's OnIdle
480
+ // handler, we have to have our top-level PowerShell instance be nested (otherwise
481
+ // we get a PSInvalidOperationException because pipelines cannot be run
482
+ // concurrently). Specifically this bug cropped up when a profile loaded code which
483
+ // registered (and subsequently ran) on the OnIdle handler since it was hitting the
484
+ // non-nested PowerShell instance. So now we just start with a nested instance.
485
+ PowerShell nestedPwsh = CreateNestedPowerShell ( localRunspaceInfo ) ;
486
+ _runspaceStack . Push ( new RunspaceFrame ( nestedPwsh . Runspace , localRunspaceInfo ) ) ;
487
+
488
+ // TODO: Should this now be marked as a Nested frame, even though for our purposes
489
+ // it isn't really nested?
490
+ PushPowerShellAndRunLoop ( nestedPwsh , PowerShellFrameType . Normal | PowerShellFrameType . Repl , localRunspaceInfo ) ;
480
491
}
481
492
catch ( Exception e )
482
493
{
You can’t perform that action at this time.
0 commit comments