@@ -457,22 +457,25 @@ public async Task<string> SetVariableAsync(int variableContainerReferenceId, str
457
457
458
458
if ( argTypeConverterAttr is not null )
459
459
{
460
+ // PSVariable *is* strongly typed, so we have to convert it.
460
461
_logger . LogTrace ( $ "Setting variable '{ name } ' using conversion to value: { expressionResult ?? "<null>" } ") ;
461
462
462
- // TODO: This is throwing a 'PSInvalidOperationException' thus causing
463
- // 'DebuggerSetsVariablesWithConversion' to fail.
464
- psVariable . Value = await _executionService . ExecuteDelegateAsync (
465
- "PS debugger argument converter" ,
466
- ExecutionOptions . Default ,
467
- ( pwsh , _ ) =>
468
- {
469
- var engineIntrinsics = ( EngineIntrinsics ) pwsh . Runspace . SessionStateProxy . GetVariable ( "ExecutionContext" ) ;
470
-
471
- // TODO: This is almost (but not quite) the same as LanguagePrimitives.Convert(), which does not require the pipeline thread.
472
- // We should investigate changing it.
473
- return argTypeConverterAttr . Transform ( engineIntrinsics , expressionResult ) ;
474
- } ,
463
+ // NOTE: We use 'Get-Variable' here instead of 'SessionStateProxy.GetVariable()'
464
+ // because we already have a pipeline running (the debugger) and the latter cannot
465
+ // run concurrently (threw 'NoSessionStateProxyWhenPipelineInProgress').
466
+ IReadOnlyList < EngineIntrinsics > results = await _executionService . ExecutePSCommandAsync < EngineIntrinsics > (
467
+ new PSCommand ( )
468
+ . AddCommand ( @"Microsoft.PowerShell.Utility\Get-Variable" )
469
+ . AddParameter ( "Name" , "ExecutionContext" )
470
+ . AddParameter ( "ValueOnly" ) ,
475
471
CancellationToken . None ) . ConfigureAwait ( false ) ;
472
+ EngineIntrinsics engineIntrinsics = results . Count > 0
473
+ ? results [ 0 ]
474
+ : throw new Exception ( "Couldn't get EngineIntrinsics!" ) ;
475
+
476
+ // TODO: This is almost (but not quite) the same as 'LanguagePrimitives.Convert()',
477
+ // which does not require the pipeline thread. We should investigate changing it.
478
+ psVariable . Value = argTypeConverterAttr . Transform ( engineIntrinsics , expressionResult ) ;
476
479
}
477
480
else
478
481
{
@@ -642,7 +645,7 @@ private Task<VariableContainerDetails> FetchVariableContainerAsync(string scope)
642
645
643
646
private async Task < VariableContainerDetails > FetchVariableContainerAsync ( string scope , bool autoVarsOnly )
644
647
{
645
- PSCommand psCommand = new PSCommand ( ) . AddCommand ( " Get-Variable") . AddParameter ( "Scope" , scope ) ;
648
+ PSCommand psCommand = new PSCommand ( ) . AddCommand ( @"Microsoft.PowerShell.Utility\ Get-Variable") . AddParameter ( "Scope" , scope ) ;
646
649
647
650
var scopeVariableContainer = new VariableContainerDetails ( nextVariableId ++ , "Scope: " + scope ) ;
648
651
variables . Add ( scopeVariableContainer ) ;
0 commit comments