diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs b/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs index 195d0508b..55434072b 100644 --- a/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs +++ b/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs @@ -477,6 +477,10 @@ public async Task<string> SetVariableAsync(int variableContainerReferenceId, str // This makes the returned string consistent with the strings normally displayed for variables in the debugger. VariableDetails tempVariable = new(psVariable); _logger.LogTrace($"Set variable '{name}' to: {tempVariable.ValueString ?? "<null>"}"); + + // Fetch stack frames and variables again to have actual data in the variables field. + // Without this, GetVariables and other methods that use the variables field will use old data. + await FetchStackFramesAndVariablesAsync(null).ConfigureAwait(false); return tempVariable.ValueString; } @@ -504,6 +508,10 @@ public async Task<VariableDetails> EvaluateExpressionAsync( command, cancellationToken, new PowerShellExecutionOptions { WriteOutputToHost = writeResultAsOutput, ThrowOnError = !writeResultAsOutput }).ConfigureAwait(false); + + // Fetch stack frames and variables again to have actual data in the variables field. + // Without this, GetVariables and other methods that use the variables field will use old data. + await FetchStackFramesAndVariablesAsync(null).ConfigureAwait(false); } catch (Exception e) {