question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unhandled exception in ConsolePal.ReadKey

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
daxian-dbwcommented, Oct 15, 2019

@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

0reactions
jazzdelightsmecommented, Jul 13, 2023

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found