Bug 40699 - Console.ReadXXX does not echo input after TermInfoDriver is initialized
Summary: Console.ReadXXX does not echo input after TermInfoDriver is initialized
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib (show other bugs)
Version: master
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Katelyn Gadd
Depends on:
Reported: 2016-04-26 12:45 UTC by Llewellyn Pritchard
Modified: 2017-11-15 17:52 UTC (History)
6 users (show)

See Also:
Tags: bugpool
Is this bug a regression?: ---
Last known good build:


Description Llewellyn Pritchard 2016-04-26 12:45:43 UTC
Tested on recent versions (4.3 and 4.5).

Not tested on Windows.

Compile and run the following program:

using System;
using System.Threading;

class Program
    static void Main(string[] args)
        string got = "";
        var w = new ManualResetEvent(false);
        Console.CancelKeyPress += (s, e) =>
        Console.WriteLine("Type something:");
        got = Console.In.ReadToEnd();
        Console.WriteLine("Got: {0}", got); 

Try type something into console, input is not echoed. 
This happens when Console.CancelKeyPress is used. 
Works fine without.
Comment 1 Llewellyn Pritchard 2016-05-06 20:29:17 UTC
Has no one noticed this bug for 10+ years?
Comment 2 Al Clark [MSFT] 2017-04-06 17:15:22 UTC
Able to replicate in latest stable Xamarin Studio and VS for Mac.

=== Visual Studio for Mac Preview ===

Version Preview 5 (7.0 build 1659)
Installation UUID: 08ed6cb4-2770-4651-b990-1029b402f099
	Mono 4.8.0 (mono-4.8.0-branch/8f6d0f6) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 408000520

=== NuGet ===


=== Xamarin.Profiler ===

Version: 1.2.1
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 8.3 (12169)
Build 8E162

=== Xamarin.iOS ===

Version: (Visual Studio Enterprise)
Hash: e66c6f19
Branch: xcode8.3
Build date: 2017-03-28 00:48:33-0400

=== Xamarin.Android ===

Version: (Visual Studio Enterprise)
Android SDK: /Users/Alan/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.4 (API level 19)
		5.1 (API level 22)
		6.0 (API level 23)
		7.1 (API level 25)

SDK Tools Version: 25.2.5
SDK Platform Tools Version: 25.0.4
SDK Build Tools Version: 25.0.2

Java SDK: /usr
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

Android Designer EPL code available here:

=== Xamarin.Mac ===

Version: (Visual Studio Enterprise)

=== Xamarin Inspector ===

Version: 1.2.0
Hash: 62c17e6
Branch: d15-1
Build date: Mon, 20 Mar 2017 02:36:23 GMT

=== Build Information ===

Release ID: 700001659
Git revision: c3bcd7708b7762fa4c12a88e7c5d75d83eb6462b
Build date: 2017-03-14 22:27:06-04
Xamarin addins: 11612bcfed8942216a2991a15e28b8d3df21449a
Build lane: monodevelop-lion-vs-mac-preview5

=== Operating System ===

Mac OS X 10.12.3
Darwin Alans-iMac.local 16.4.0 Darwin Kernel Version 16.4.0
    Thu Dec 22 22:53:21 PST 2016
    root:xnu-3789.41.3~3/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Android Signature Tool 2.1.2
Comment 3 Ludovic Henry 2017-10-06 20:48:44 UTC
I can reproduce with Mono (2017-10/a3943e28cf8)
Comment 4 Katelyn Gadd 2017-11-15 05:42:27 UTC
Another possible bug here is that ctrl+c does not ever print 'Got:' in Mono on Linux, but the Windows .NET Framework does print it along with the text that was entered.
Comment 5 Katelyn Gadd 2017-11-15 06:55:27 UTC
It appears that any operation that initializes the unix terminal driver will break input echoing. You can remove the CancelKeyPress event handler and it is still broken, or you can initialize the driver a different way (like reading Console.BufferWidth, for example.) So as a result this reduced repro also demonstrates the issue:

using System;

class Program
    static void Main(string[] args)
        var bufferWidth = Console.BufferWidth;
        Console.WriteLine("Type something:");
        var got = Console.In.ReadToEnd();
        Console.WriteLine("Got: {0}", got); 
Comment 6 Katelyn Gadd 2017-11-15 17:52:16 UTC
Fixed by https://github.com/mono/mono/pull/6016.

Note You need to log in before you can comment on or make changes to this bug.