Skip to content

Console.KeyAvailable throws when input isn't redirected on Windows 7 x86  #43015

Description

@ViktorHofer
[xUnit.net 00:00:03.88]     ReadKey.KeyAvailable [FAIL]
[xUnit.net 00:00:03.88]       System.InvalidOperationException : Cannot see if a key has been pressed when either application does not have a console or when console input has been redirected from a file. Try Console.In.Peek.
[xUnit.net 00:00:03.88]       Stack Trace:
[xUnit.net 00:00:03.89]         /_/src/libraries/System.Console/src/System/ConsolePal.Windows.cs(278,0): at System.ConsolePal.get_KeyAvailable()
[xUnit.net 00:00:03.89]         /_/src/libraries/System.Console/src/System/Console.cs(153,0): at System.Console.get_KeyAvailable()
[xUnit.net 00:00:03.89]         /_/src/libraries/System.Console/tests/ReadKey.cs(21,0): at ReadKey.KeyAvailable()

Additional logging:

 fileTypeOutput 'input': 2
 IsInputHandleRedirected: False

The docs state that fileType 2 means:

The specified file is a character file, typically an LPT device or a console.

I would assume that in such a case an InvalidOperationException shouldn't happen. Also this seems to be specific to Windows 7 x86.

cc @eiriktsarpalis

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions