Unhandled exception. System.InvalidOperationException: Cannot read keys when either application does not have a console or when console input has been redirected #6954

Closed
opened 2026-01-31 00:51:28 +00:00 by claunia · 12 comments
Owner

Originally created by @SergioMorchon on GitHub (Mar 18, 2020).

Environment

Windows build number: Win32NT, 10.0.18363.0, Microsoft Windows NT 10.0.18363.0:

Steps to reproduce

Using:

  1. I start the dev server and leave it run in this terminal.
  2. After some time of working between vscode and the web browser.
  3. I come back to the console and hit Ctrl+C to stop the process and do other stuff.

Expected behavior

To behave as a normal Ctrl+C, and continue using the same terminal tab.

Actual behavior

It shows an exception:

PS C:\Users\smorchon\dev\webapp\web>
An error has occurred that was not properly handled. Additional information is shown below. The PowerShell process will
exit.
Unhandled exception. System.InvalidOperationException: Cannot read keys when either application does not have a console
or when console input has been redirected. Try Console.Read.
   at System.ConsolePal.ReadKey(Boolean intercept)
   at System.Console.ReadKey(Boolean intercept)
   at Microsoft.PowerShell.Internal.VirtualTerminal.ReadKey()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadOneOrMoreKeys()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadKeyThreadProc()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object
state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object
state)
   at System.Threading.ThreadHelper.ThreadStart()

[process exited with code 3762504530]

And after that, I can only close that terminal tab and continue un a new one.

Originally created by @SergioMorchon on GitHub (Mar 18, 2020). # Environment ``` Windows build number: Win32NT, 10.0.18363.0, Microsoft Windows NT 10.0.18363.0: ``` # Steps to reproduce Using: * pwsh `v7.0.0`. * [yarn|https://yarnpkg.com/] `v1.22.0`. * [node|https://nodejs.org/en/] `v12.16.1`. * [webpack dev server|https://webpack.js.org/configuration/dev-server/] `3.9.0`. 1. I start the dev server and leave it run in this terminal. 1. After some time of working between vscode and the web browser. 1. I come back to the console and hit `Ctrl+C` to stop the process and do other stuff. # Expected behavior To behave as a normal `Ctrl+C`, and continue using the same terminal tab. # Actual behavior It shows an exception: ``` PS C:\Users\smorchon\dev\webapp\web> An error has occurred that was not properly handled. Additional information is shown below. The PowerShell process will exit. Unhandled exception. System.InvalidOperationException: Cannot read keys when either application does not have a console or when console input has been redirected. Try Console.Read. at System.ConsolePal.ReadKey(Boolean intercept) at System.Console.ReadKey(Boolean intercept) at Microsoft.PowerShell.Internal.VirtualTerminal.ReadKey() at Microsoft.PowerShell.PSConsoleReadLine.ReadOneOrMoreKeys() at Microsoft.PowerShell.PSConsoleReadLine.ReadKeyThreadProc() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location where exception was thrown --- at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() [process exited with code 3762504530] ``` And after that, I can only close that terminal tab and continue un a new one.
claunia added the Needs-Tag-FixResolution-No-ReproNeeds-AttentionNeeds-Repro labels 2026-01-31 00:51:28 +00:00
Author
Owner

@DHowett-MSFT commented on GitHub (Mar 18, 2020):

How did you install PowerShell?

@DHowett-MSFT commented on GitHub (Mar 18, 2020): How did you install PowerShell?
Author
Owner

@SergioMorchon commented on GitHub (Mar 19, 2020):

It is using Windows.Terminal.PowershellCore. I don't see Powershell in the settings application list (not Powershell nor pwsh there)
Here's the setting for the terminal:

      {
        "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
        "hidden": false,
        "name": "PowerShell",
        "source": "Windows.Terminal.PowershellCore",
        "startingDirectory": "%USERPROFILE%/dev"
      },
@SergioMorchon commented on GitHub (Mar 19, 2020): It is using `Windows.Terminal.PowershellCore`. I don't see Powershell in the settings application list (not _Powershell_ nor _pwsh_ there) Here's the setting for the terminal: ``` { "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}", "hidden": false, "name": "PowerShell", "source": "Windows.Terminal.PowershellCore", "startingDirectory": "%USERPROFILE%/dev" }, ```
Author
Owner

@DHowett-MSFT commented on GitHub (Mar 19, 2020):

Okay, that’s powershell core. How did you install it?

@DHowett-MSFT commented on GitHub (Mar 19, 2020): Okay, that’s powershell core. How did you install it?
Author
Owner

@SergioMorchon commented on GitHub (Mar 19, 2020):

Maybe through dotnet core:

PS C:\Users\smorchon\dev> wsl which pwsh.exe
/mnt/c/Users/smorchon/.dotnet/tools/.store/powershell/7.0.0/powershell/7.0.0/tools/netcoreapp3.1/any/win/pwsh.exe
@SergioMorchon commented on GitHub (Mar 19, 2020): Maybe through dotnet core: ``` PS C:\Users\smorchon\dev> wsl which pwsh.exe /mnt/c/Users/smorchon/.dotnet/tools/.store/powershell/7.0.0/powershell/7.0.0/tools/netcoreapp3.1/any/win/pwsh.exe ```
Author
Owner

@DHowett-MSFT commented on GitHub (Mar 19, 2020):

This looks like another version of https://github.com/PowerShell/PowerShell/issues/11314 -- but it really looks like node or yarn or something is closing the console handle and PowerShell is crashing because of it.

Does this happen outside of Terminal?

@DHowett-MSFT commented on GitHub (Mar 19, 2020): This looks like another version of https://github.com/PowerShell/PowerShell/issues/11314 -- but it really looks like node or yarn or something is closing the console handle and PowerShell is crashing because of it. Does this happen _outside_ of Terminal?
Author
Owner

@ghost commented on GitHub (Mar 24, 2020):

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@ghost commented on GitHub (Mar 24, 2020): This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for **4 days**. It will be closed if no further activity occurs **within 3 days of this comment**.
Author
Owner

@SergioMorchon commented on GitHub (Mar 24, 2020):

Sorry, but I cannot reproducet it anymore after installing PowerShell 7 from the repo (the PowerShell-7.0.0-win-x64.msi file from here https://github.com/PowerShell/PowerShell/releases/tag/v7.0.0).
Looks like after a day using the same dev server but on that powershell installation works as expected, without the Ctrl+C issue I mentioned.

@SergioMorchon commented on GitHub (Mar 24, 2020): Sorry, but I cannot reproducet it anymore after installing PowerShell 7 from the repo (the `PowerShell-7.0.0-win-x64.msi` file from here https://github.com/PowerShell/PowerShell/releases/tag/v7.0.0). Looks like after a day using the same dev server but on that powershell installation works as expected, without the Ctrl+C issue I mentioned.
Author
Owner

@DHowett-MSFT commented on GitHub (Mar 24, 2020):

That's very strange. Thanks for following up!

@DHowett-MSFT commented on GitHub (Mar 24, 2020): That's very strange. Thanks for following up!
Author
Owner

@EmperorRXF commented on GitHub (Mar 21, 2021):

I believe I'm having this same issue, and have managed to setup a reproducible scenario for it. It also only happens with the combination of yarn v1 & powershell core. If I happen to use cmd or windows powershell, then the issue doesn't happen.

Using:

windows OS - Microsoft Windows 10.0.19042
powershell core - v7.1.3
windows powershell - v5.1.19041.610
node - v14.15.0
yarn - v1.22.10

Steps to reproduce:

  1. ensure node & yarn is installed.
  2. clone the repo from - https://github.com/EmperorRXF/pscore-yarn-error
  3. from the cloned root, run yarn
  4. run yarn dev (this will make node execute a long-running task, and log to the console)
  5. while the task is running, hit CTRL+C to terminate the yarn process, and you'll notice the following error and the pscore process will crash
    image
@EmperorRXF commented on GitHub (Mar 21, 2021): I believe I'm having this same issue, and have managed to setup a reproducible scenario for it. It also only happens with the combination of `yarn v1` & `powershell core`. If I happen to use `cmd` or `windows powershell`, then the issue doesn't happen. ### Using: windows OS - Microsoft Windows 10.0.19042 powershell core - v7.1.3 windows powershell - v5.1.19041.610 node - v14.15.0 yarn - v1.22.10 ### Steps to reproduce: 1. ensure `node` & `yarn` is installed. 2. clone the repo from - `https://github.com/EmperorRXF/pscore-yarn-error` 3. from the cloned root, run `yarn` 4. run `yarn dev` (this will make node execute a long-running task, and log to the console) 5. while the task is running, hit CTRL+C to terminate the yarn process, and you'll notice the following error and the pscore process will crash ![image](https://user-images.githubusercontent.com/8752394/111908539-aa71da80-8a7f-11eb-9a56-e74ab4eb2232.png)
Author
Owner

@lokinmodar commented on GitHub (Feb 14, 2022):

I believe I'm having this same issue, and have managed to setup a reproducible scenario for it. It also only happens with the combination of yarn v1 & powershell core. If I happen to use cmd or windows powershell, then the issue doesn't happen.

Using:

windows OS - Microsoft Windows 10.0.19042 powershell core - v7.1.3 windows powershell - v5.1.19041.610 node - v14.15.0 yarn - v1.22.10

Steps to reproduce:

  1. ensure node & yarn is installed.
  2. clone the repo from - https://github.com/EmperorRXF/pscore-yarn-error
  3. from the cloned root, run yarn
  4. run yarn dev (this will make node execute a long-running task, and log to the console)
  5. while the task is running, hit CTRL+C to terminate the yarn process, and you'll notice the following error and the pscore process will crash
    image

did you manage to solve this?

@lokinmodar commented on GitHub (Feb 14, 2022): > I believe I'm having this same issue, and have managed to setup a reproducible scenario for it. It also only happens with the combination of `yarn v1` & `powershell core`. If I happen to use `cmd` or `windows powershell`, then the issue doesn't happen. > > ### Using: > windows OS - Microsoft Windows 10.0.19042 powershell core - v7.1.3 windows powershell - v5.1.19041.610 node - v14.15.0 yarn - v1.22.10 > > ### Steps to reproduce: > 1. ensure `node` & `yarn` is installed. > 2. clone the repo from - `https://github.com/EmperorRXF/pscore-yarn-error` > 3. from the cloned root, run `yarn` > 4. run `yarn dev` (this will make node execute a long-running task, and log to the console) > 5. while the task is running, hit CTRL+C to terminate the yarn process, and you'll notice the following error and the pscore process will crash > ![image](https://user-images.githubusercontent.com/8752394/111908539-aa71da80-8a7f-11eb-9a56-e74ab4eb2232.png) did you manage to solve this?
Author
Owner

@alfawal commented on GitHub (Apr 8, 2022):

@DHowett-MSFT I believe that this error is occurring again, can you reopen the issue?
NOTE: This is happening sometimes only when pressing CTRL+C while using nodemon.

@alfawal commented on GitHub (Apr 8, 2022): @DHowett-MSFT I believe that this error is occurring again, can you reopen the issue? NOTE: This is happening sometimes only when pressing <kbd>CTRL</kbd>+<kbd>C</kbd> while using `nodemon`.
Author
Owner

@zadjii-msft commented on GitHub (Apr 8, 2022):

@alfawal this was originally root caused to a PowerShell issue: https://github.com/PowerShell/PowerShell/issues/11314

I might recommend following up with them, since it seems to be an issue with the way they're handling ^C

@zadjii-msft commented on GitHub (Apr 8, 2022): @alfawal this was originally root caused to a PowerShell issue: https://github.com/PowerShell/PowerShell/issues/11314 I might recommend following up with them, since it seems to be an issue with the way they're handling ^C
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#6954