Skip to content

Unhandled exception in ConsolePal.ReadKey #1099

Closed

Description

@edyoung

Steps to reproduce

I don't have a consistent repro, sorry. See version details below. Typed c space d backspace backspace, pwsh hung for about 10 seconds then produced error below and exited

PS C:\onebranch> c
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.PSConsoleReadLine.ReadOneOrMoreKeys()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadKeyThreadProc()
   at System.Threading.Thread.ThreadMain_ThreadStart()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

Expected behavior

Don't crash

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.1.0
PSEdition                      Core
GitCommitId                    6.1.0
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. iSazonov commented on Oct 11, 2018

    @iSazonov

    We need repo.

  2. SteveL-MSFT commented on Oct 11, 2018

    @SteveL-MSFT
    Member

    Can you open this in the PSReadLine repo? PSConsoleReadLine is coming from PSReadLine

  3. iSazonov commented on Oct 13, 2019

    @iSazonov

    Dongbo Wang (@daxian-dbw) Could you please make a conclusion about the issue while you is on the wave?

  4. daxian-dbw commented on Oct 15, 2019

    @daxian-dbw
    Member

    Ilya (@iSazonov) I cannot. I cannot reproduce this, and the reported exception was thrown from the .NET Core code. Hope it's fixed in the .NET Core 3.0

  5. iSazonov commented on Oct 16, 2019

    @iSazonov
  6. daxian-dbw commented on Oct 16, 2019

    @daxian-dbw
    Member

    Close the issue because

    1. cannot reproduce the issue
    2. exception is thrown from System.Console.ReadKey, which is .NET Core code.
  7. jazzdelightsme commented on Jul 13, 2023

    @jazzdelightsme
    Contributor

    This problem could be caused by: dotnet/runtime#88697

    I plan to open a new Issue for how this could be addressed in PSReadLine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions