Unhandled exception in ConsolePal.ReadKey
See original GitHub issueSteps 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
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
ReadKey InvalidOperationException application does not ...
Exception has occurred: CLR/System.InvalidOperationException An unhandled exception of type 'System.InvalidOperationException' occurred in ...
Read more >Unhandled exception. System.InvalidOperationException
Unhandled exception. System.InvalidOperationException: Cannot read keys when either application does not have a console or when console ...
Read more >Console.ReadKey not working when debugging C# .Net
I get the following error: Exception has occurred: CLR/System.InvalidOperationException An unhandled exception of type 'System.
Read more >DataServer error while starting
Unhandled exception. System.InvalidOperationException: Cannot read keys when either application does not have a console or when console input ...
Read more >dotnet-stack diagnostic tool - .NET CLI
Captures and prints the managed stacks for all threads in the target .NET process. Utilizes EventPipe tracing provided by the .NET Core runtime....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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
This problem could be caused by: https://github.com/dotnet/runtime/issues/88697
I plan to open a new Issue for how this could be addressed in PSReadLine.