You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Setting Console.TreatControlCAsInput to true causes text to be removable #44667
For some reason, setting Console.TreatControlCAsInput to 'true' causes text printed with "Console.Write" to be removable. To reproduce, simply create a new Console application and paste the following code in the main method:
//Console.TreatControlCAsInput = true;
Console.Write("Test> ");
while (true) Console.Read();
Start the application (with the first line commented) and write some input. Then hold down backspace; the text should remove until the end of "Test> " and you aren't able to remove more characters.
Now uncomment the first line and start the application again. Write some input and hold down backspace; for some reason now every text is removed with backspace, even what was printed with Console.Write.
Original Comments
Feedback Bot on 5/21/2020, 03:45 AM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Feedback Bot on 7/2/2020, 11:17 PM:
I have detected that for the last 35 days, this issue didn't have much product team activity and a very small amount of new votes or comments. Based on this, its severity, and affected area, it’s my experience that this issue is very unlikely to be fixed.
The issue is in the TreatControlCAsInput setter in ConsolePal.Windows.cs.
It toggles ENABLE_PROCESSED_INPUT alone, but leaves ENABLE_LINE_INPUT on.
When these two flags are mismatched, the console's built-in line editor stays
active but loses its boundary logic, so backspace has no lower bound and crawls
into already-printed output.
The fix is to always toggle both flags together, since ENABLE_LINE_INPUT
depends on ENABLE_PROCESSED_INPUT to function correctly. This is safe because ReadKey() — the natural companion to this property — reads via ReadConsoleInput and never relied on ENABLE_LINE_INPUT to begin with.
if(value){mode&=~Interop.Kernel32.ENABLE_PROCESSED_INPUT;mode&=~Interop.Kernel32.ENABLE_LINE_INPUT;// must be disabled together}else{mode|=Interop.Kernel32.ENABLE_PROCESSED_INPUT;mode|=Interop.Kernel32.ENABLE_LINE_INPUT;// must be restored together}
If you think this is a good idea let me now and I will craete a PR for it
I am not familiar with this exact logic, but if you can prove that given change is fixing the bug (this needs manual verification, most likely using corerun.exe for given local build) please go ahead and send the PR.
This reproduces on the console host of 2020 and not on today's. Under OpenConsole.exe from Windows Terminal v1.0.1401.0 (published 2020-05-19), the repro from this issue loses the whole Test> prompt to a held backspace. Under inbox conhost on Windows 11 build 26200 the same keystrokes echo as ^H and erase nothing.
The change was in the console host, not in .NET. Results match on .NET Core 3.1.4, .NET Framework 4.8 and .NET 10.0.12, and the setter's flag handling is unchanged since 2016.
Clearing ENABLE_LINE_INPUT as well is not a fix.SetConsoleMode rejects echo without line input, and with echo cleared too the prompt survives on the 2020 host only because nothing typed is shown.
Source read at d84e42c1ca2; methods are in the note at the end.
The ask
The reported symptom is gone from the console host, and no combination of these flags restores a lower bound for backspace. Can this be closed as fixed in the console host, or should it stay open for Windows 10, whose inbox conhost I have not tested?
The repro from this issue, on both hosts
This issue's program plus a quit key and screen dump, on .NET 10.0.12. Keystrokes: helloworld, 25 backspaces, q.
host
property untouched
TreatControlCAsInput = true
OpenConsole.exe 1.0.200517002
Test> q
q at the end of the row above Test>
inbox conhost, build 26200
Test> q
Test> helloworld then 25 ^H then q
By hand, the 2020 host puts q in the same place and leaves the Test> helloworld row blank.
Where the host changed
Row 0 with the property set, after abc, eight backspaces and Enter:
OpenConsole.exe from Windows Terminal
row 0
v1.0.1401.0, v1.18.2681.0
T
v1.19.2682.0, v1.19.2831.0 (previews)
T abc
v1.19.3172.0 (preview), and one preview from each of v1.20 to v1.25
Test> abc^H^H^H^H^H^H^H^H
inbox conhost, build 26200
Test> abc^H^H^H^H^H^H^H^H
The likely change in v1.19.2831.0...v1.19.3172.0 is microsoft/terminal#16105, which moved the "interactive" mode of WriteCharsLegacy into COOKED_READ_DATA, where the new writer prints control characters other than tab as caret pairs such as ^H. Read from the diff, not bisected.
Clearing ENABLE_LINE_INPUT as well
The change suggested earlier in this thread leaves echo on, so from the default 0x01F7 it asks for 0x01F4. SetConsoleMode rejects that with error 87 and applies it anyway; built into System.Console, the setter threw IOException: "The parameter is incorrect." Clearing ENABLE_ECHO_INPUT too is accepted, and the prompt then survives on the 2020 host, but nothing typed appears and ReadLine() returns the backspaces as \b.
Note
AI-generated, written at my direction and reviewed by me before posting. Source read at d84e42c1ca2. Everything ran on Windows 11 build 26200, under inbox conhost or standalone OpenConsole.exe builds from Windows Terminal releases, with the host confirmed from the process tree. The repro rows come from this issue's program, its keystrokes written into its console from a separate process (AttachConsole + WriteConsoleInput); one repeat was typed on a keyboard. The mode results come from a harness that sets each input mode, writes abc, eight backspaces and Enter into its own console and reads the screen buffer back while the read is pending, on .NET Core 3.1.4, .NET Framework 4.8 and .NET 10.0.12. The exception is from the suggested change, plus an ENABLE_LINE_INPUT constant, built in src/libraries/System.Console and run against the repo testhost, with a reverted rebuild as the control.
Activity
eiriktsarpalis commentedon Nov 16, 2020
The issue reproduces on Windows only (both in .NET Core and framework). Linux is unaffected.
Neo-vortex commentedon May 20, 2026
The issue is in the
TreatControlCAsInputsetter inConsolePal.Windows.cs.It toggles
ENABLE_PROCESSED_INPUTalone, but leavesENABLE_LINE_INPUTon.When these two flags are mismatched, the console's built-in line editor stays
active but loses its boundary logic, so backspace has no lower bound and crawls
into already-printed output.
The fix is to always toggle both flags together, since
ENABLE_LINE_INPUTdepends on
ENABLE_PROCESSED_INPUTto function correctly. This is safe becauseReadKey()— the natural companion to this property — reads viaReadConsoleInputand never relied onENABLE_LINE_INPUTto begin with.@eiriktsarpalis, @adamsitnik If you think this is a good idea let me now and I will craete a PR for it
adamsitnik commentedon May 21, 2026
I am not familiar with this exact logic, but if you can prove that given change is fixing the bug (this needs manual verification, most likely using
corerun.exefor given local build) please go ahead and send the PR.caraioniurie47 commentedon Sep 13, 2026
Summary
OpenConsole.exefrom Windows Terminal v1.0.1401.0 (published 2020-05-19), the repro from this issue loses the wholeTest>prompt to a held backspace. Under inbox conhost on Windows 11 build 26200 the same keystrokes echo as^Hand erase nothing.ENABLE_LINE_INPUTas well is not a fix.SetConsoleModerejects echo without line input, and with echo cleared too the prompt survives on the 2020 host only because nothing typed is shown.Console.ReadLine()returns each line one Enter late in this mode; filed asConsole.ReadLine()returns each line one Enter late whenConsole.TreatControlCAsInputistrueon Windows #133814.Source read at
d84e42c1ca2; methods are in the note at the end.The ask
The reported symptom is gone from the console host, and no combination of these flags restores a lower bound for backspace. Can this be closed as fixed in the console host, or should it stay open for Windows 10, whose inbox conhost I have not tested?
The repro from this issue, on both hosts
This issue's program plus a quit key and screen dump, on .NET 10.0.12. Keystrokes:
helloworld, 25 backspaces,q.TreatControlCAsInput = trueOpenConsole.exe1.0.200517002Test> qqat the end of the row aboveTest>Test> qTest> helloworldthen 25^HthenqBy hand, the 2020 host puts
qin the same place and leaves theTest> helloworldrow blank.Where the host changed
Row 0 with the property set, after
abc, eight backspaces and Enter:OpenConsole.exefrom Windows TerminalTT abcTest> abc^H^H^H^H^H^H^H^HTest> abc^H^H^H^H^H^H^H^HThe likely change in
v1.19.2831.0...v1.19.3172.0is microsoft/terminal#16105, which moved the "interactive" mode ofWriteCharsLegacyintoCOOKED_READ_DATA, where the new writer prints control characters other than tab as caret pairs such as^H. Read from the diff, not bisected.Clearing
ENABLE_LINE_INPUTas wellThe change suggested earlier in this thread leaves echo on, so from the default
0x01F7it asks for0x01F4.SetConsoleModerejects that with error 87 and applies it anyway; built intoSystem.Console, the setter threwIOException: "The parameter is incorrect." ClearingENABLE_ECHO_INPUTtoo is accepted, and the prompt then survives on the 2020 host, but nothing typed appears andReadLine()returns the backspaces as\b.Note
AI-generated, written at my direction and reviewed by me before posting. Source read at
d84e42c1ca2. Everything ran on Windows 11 build 26200, under inbox conhost or standaloneOpenConsole.exebuilds from Windows Terminal releases, with the host confirmed from the process tree. The repro rows come from this issue's program, its keystrokes written into its console from a separate process (AttachConsole+WriteConsoleInput); one repeat was typed on a keyboard. The mode results come from a harness that sets each input mode, writesabc, eight backspaces and Enter into its own console and reads the screen buffer back while the read is pending, on .NET Core 3.1.4, .NET Framework 4.8 and .NET 10.0.12. The exception is from the suggested change, plus anENABLE_LINE_INPUTconstant, built insrc/libraries/System.Consoleand run against the repo testhost, with a reverted rebuild as the control.adamsitnik commentedon Sep 14, 2026
If it does not reproduce on modern console host, we can just close it as the bug has been reported only once and received 0 upvotes over the years.