Skip to content

Unexpected token 'eval' in expression or statement when using the PowerShell Extension in Debug Mode #5145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
6 tasks done
BrooksV opened this issue Feb 23, 2025 · 3 comments
Labels
Issue-Bug A bug to squash. Needs: Author Feedback Please give us the requested feedback!

Comments

@BrooksV
Copy link

BrooksV commented Feb 23, 2025

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

I am running this very simple PowerShell WPF script using VS Code PowerShell Extension by executing (Run). After I close the form and check $error, It always contains the same error. If I execute using or in a pwsh Terminal, $error has not errors. It seems to be directly related to using the Debugger in VS Code.

Note: The $Error contents also show up in this log File (C:\Users\MySelf\AppData\Roaming\Code\logs\20250220T121920\window4\exthost\ms-vscode.powershell\PowerShell.log).

Here is the output and $Error:

PowerShell Extension v2025.0.0
Copyright (c) Microsoft Corporation.

https://aka.ms/vscode-powershell
Type 'help' to get help.

PS C:\Git\SqlQueryEditor> 
PS C:\Git\SqlQueryEditor> . 'C:\Git\SqlQueryEditor\archive\Test-01.ps1'
Form is closing. Cleaning up resources.
PS C:\Git\SqlQueryEditor> $error

Errors                      : {At line:1 char:47
                              + [System.Diagnostics.DebuggerHidden()]param() ,eval $stdout.sync=true
                              +                                               ~
                              Missing expression after unary operator ','., At line:1 char:47
                              + [System.Diagnostics.DebuggerHidden()]param() ,eval $stdout.sync=true
                              +                                               ~~~~
                              Unexpected token 'eval' in expression or statement.}
Message                     : At line:1 char:47
                              + [System.Diagnostics.DebuggerHidden()]param() ,eval $stdout.sync=true
                              +                                               ~
                              Missing expression after unary operator ','.

                              At line:1 char:47
                              + [System.Diagnostics.DebuggerHidden()]param() ,eval $stdout.sync=true
                              +                                               ~~~~
                              Unexpected token 'eval' in expression or statement.
ErrorRecord                 : At line:1 char:47
                              + [System.Diagnostics.DebuggerHidden()]param() ,eval $stdout.sync=true
                              +                                               ~
                              Missing expression after unary operator ','.

                              At line:1 char:47
                              + [System.Diagnostics.DebuggerHidden()]param() ,eval $stdout.sync=true
                              +                                               ~~~~
                              Unexpected token 'eval' in expression or statement.
WasThrownFromThrowStatement : False
TargetSite                  : System.Collections.ObjectModel.Collection`1[System.Management.Automation.PSObject] Invoke(System.Collections.IEnumerable)
Data                        : {}
InnerException              : 
HelpLink                    : 
Source                      : System.Management.Automation
HResult                     : -2146233087
StackTrace                  :    at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
                                 at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
                                 at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
                                 at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
                                 at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
                                 at System.Management.Automation.PowerShell.Invoke[T](IEnumerable input, PSInvocationSettings settings)
                                 at Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.PowerShellExtensions.InvokeAndClear[TResult](PowerShell pwsh, PSInvocationSettings invocationSettings) in
                              C:\__w\1\s\src\PowerShellEditorServices\Services\PowerShell\Utility\PowerShellExtensions.cs:line 76
                                 at Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.PowerShellExtensions.InvokeCommand[TResult](PowerShell pwsh, PSCommand psCommand, PSInvocationSettings invocationSettings) in
                              C:\__w\1\s\src\PowerShellEditorServices\Services\PowerShell\Utility\PowerShellExtensions.cs:line 99
                                 at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousPowerShellTask`1.ExecuteNormally(CancellationToken cancellationToken) in
                              C:\__w\1\s\src\PowerShellEditorServices\Services\PowerShell\Execution\SynchronousPowerShellTask.cs:line 136

PS C:\Git\SqlQueryEditor>
# Load the required assembly
Add-Type -AssemblyName System.Windows.Forms

$Error.Clear()

# Create a simple form
$form = New-Object System.Windows.Forms.Form
$form.Text = "Simple Form"

# Handle the form's Closing event
$form.Add_Closing({
    Write-Host "Form is closing. Cleaning up resources."
})

# Show the form
$form.ShowDialog() | Out-Null

PowerShell Version

$PSVersionTable; $Host   

Name                           Value
----                           -----
PSVersion                      7.5.0
PSEdition                      Core
GitCommitId                    7.5.0
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Name             : Visual Studio Code Host
Version          : 2025.0.0
InstanceId       : 82f299f5-ef04-4dbc-9caf-1b49261fa09c
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Visual Studio Code Version

code --version                                                                                                     
1.97.2
e54c774e0add60467559eb0d1e229c6452cf8447
x64

Extension Version

code --list-extensions --show-versions | Select-String powershell

[email protected]

Steps to Reproduce

Save the following script to a file:

# Load the required assembly
Add-Type -AssemblyName System.Windows.Forms

$Error.Clear()

# Create a simple form
$form = New-Object System.Windows.Forms.Form
$form.Text = "Simple Form"

# Handle the form's Closing event
$form.Add_Closing({
    Write-Host "Form is closing. Cleaning up resources."
})

# Show the form
$form.ShowDialog() | Out-Null

Using VS Code configured with the PowerShell Extension, Run the debugger by executing (Run).
After closing the form and check $error.

Visuals

No response

Logs

Log File (C:\Users\MySelf\AppData\Roaming\Code\logs\20250220T121920\window4\exthost\ms-vscode.powershell\PowerShell.log) Contents:

2025-02-23 17:40:19.525 [info] [PSES] [Warn  - 5:40:19 PM] <Warning>Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.PsesInternalHost: Runtime exception occurred while executing command:

System.Management.Automation.ParseException: At line:1 char:47
+ [System.Diagnostics.DebuggerHidden()]param() ,eval $stdout.sync=true
+                                               ~
Missing expression after unary operator ','.

At line:1 char:47
+ [System.Diagnostics.DebuggerHidden()]param() ,eval $stdout.sync=true
+                                               ~~~~
Unexpected token 'eval' in expression or statement.
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
   at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.PowerShellExtensions.InvokeAndClear[TResult](PowerShell pwsh, PSInvocationSettings invocationSettings) in C:\__w\1\s\src\PowerShellEditorServices\Services\PowerShell\Utility\PowerShellExtensions.cs:line 76
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousPowerShellTask`1.ExecuteNormally(CancellationToken cancellationToken) in C:\__w\1\s\src\PowerShellEditorServices\Services\PowerShell\Execution\SynchronousPowerShellTask.cs:line 108 | 
2025-02-23 17:59:32.882 [warning] PowerShell process terminated or Extension Terminal was closed, PID: 30660
2025-02-23 17:59:32.882 [error] The PowerShell Extension Terminal has stopped, would you like to restart it? IntelliSense and other features will not work without it!
2025-02-23 17:59:33.413 [info] Language service connection closed.
2025-02-23 17:59:33.415 [info] [PSES] [Error - 5:59:33 PM] Connection to PowerShell Editor Services (the Extension Terminal) was closed. See below prompt to restart!
2025-02-23 17:59:35.138 [info] Restarting session...
2025-02-23 17:59:35.147 [info] Starting 'PowerShell (x64)' at: C:\Program Files\PowerShell\7\pwsh.exe
2025-02-23 17:59:35.361 [info] PowerShell process started with PID: 31932
2025-02-23 17:59:38.627 [info] Started PowerShell v7.5.0.
2025-02-23 17:59:39.023 [info] PowerShell is up-to-date.
2025-02-23 17:59:52.665 [info] [PSES] [Warn  - 5:59:52 PM] <Warning>Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.PsesInternalHost: Runtime exception occurred while executing command:

System.Management.Automation.ParseException: At line:1 char:47
+ [System.Diagnostics.DebuggerHidden()]param() ,eval $stdout.sync=true
+                                               ~
Missing expression after unary operator ','.

At line:1 char:47
+ [System.Diagnostics.DebuggerHidden()]param() ,eval $stdout.sync=true
+                                               ~~~~
Unexpected token 'eval' in expression or statement.
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
   at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke[T](IEnumerable input, PSInvocationSettings settings)
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.PowerShellExtensions.InvokeAndClear[TResult](PowerShell pwsh, PSInvocationSettings invocationSettings) in C:\__w\1\s\src\PowerShellEditorServices\Services\PowerShell\Utility\PowerShellExtensions.cs:line 76
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.PowerShellExtensions.InvokeCommand[TResult](PowerShell pwsh, PSCommand psCommand, PSInvocationSettings invocationSettings) in C:\__w\1\s\src\PowerShellEditorServices\Services\PowerShell\Utility\PowerShellExtensions.cs:line 99
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousPowerShellTask`1.ExecuteNormally(CancellationToken cancellationToken) in C:\__w\1\s\src\PowerShellEditorServices\Services\PowerShell\Execution\SynchronousPowerShellTask.cs:line 136 | 
@BrooksV BrooksV added Issue-Bug A bug to squash. Needs: Triage Maintainer attention needed! labels Feb 23, 2025
@JustinGrote
Copy link
Collaborator

I can't reproduce, works fine for me.

20250223-2317-39.2989412.mp4

@andyleejordan
Copy link
Member

Hi, do you have something in your "Watch" pane, perhaps for a different language you were using in your workspace? It's still going to run, and it does not look like PowerShell code. You'll need to remove other watch expressions.

Image

@andyleejordan andyleejordan added Needs: Author Feedback Please give us the requested feedback! and removed Needs: Triage Maintainer attention needed! labels Feb 25, 2025
Copy link
Contributor

github-actions bot commented Mar 4, 2025

This issue has been labeled as needing feedback and has not had any activity a week. It has been closed for housekeeping purposes.

@github-actions github-actions bot closed this as completed Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug A bug to squash. Needs: Author Feedback Please give us the requested feedback!
Projects
None yet
Development

No branches or pull requests

3 participants