@@ -522,7 +522,7 @@ await Task.Factory.StartNew<IEnumerable<TResult>>(
522
522
if ( ! e . SerializedRemoteException . TypeNames [ 0 ] . EndsWith ( "PipelineStoppedException" ) )
523
523
{
524
524
// Rethrow anything that isn't a PipelineStoppedException
525
- throw e ;
525
+ throw ;
526
526
}
527
527
}
528
528
@@ -608,7 +608,18 @@ await Task.Factory.StartNew<IEnumerable<TResult>>(
608
608
}
609
609
finally
610
610
{
611
- // Get the new prompt before releasing the runspace handle
611
+ // If the RunspaceAvailability is None, it means that the runspace we're in is dead.
612
+ // If this is the case, we should abort the execution which will clean up the runspace
613
+ // (and clean up the debugger) and then pop it off the stack.
614
+ // An example of when this happens is when the "attach" debug config is used and the
615
+ // process you're attached to dies randomly.
616
+ if ( this . CurrentRunspace . Runspace . RunspaceAvailability == RunspaceAvailability . None )
617
+ {
618
+ this . AbortExecution ( ) ;
619
+ this . PopRunspace ( ) ;
620
+ }
621
+
622
+ // Get the new prompt before releasing the runspace:?> handle
612
623
if ( executionOptions . WriteOutputToHost )
613
624
{
614
625
SessionDetails sessionDetails = null ;
@@ -792,10 +803,10 @@ public async Task ExecuteScriptWithArgs(string script, string arguments = null,
792
803
793
804
var strBld = new StringBuilder ( ) ;
794
805
795
- // The script parameter can refer to either a "script path" or a "command name". If it is a
806
+ // The script parameter can refer to either a "script path" or a "command name". If it is a
796
807
// script path, we can determine that by seeing if the path exists. If so, we always single
797
808
// quote that path in case it includes special PowerShell characters like ', &, (, ), [, ] and
798
- // <space>. Any embedded single quotes are escaped.
809
+ // <space>. Any embedded single quotes are escaped.
799
810
// If the provided path is already quoted, then File.Exists will not find it.
800
811
// This keeps us from quoting an already quoted path.
801
812
// Related to issue #123.
0 commit comments