Skip to content

Setting Console.TreatControlCAsInput to true causes text to be removable #44667

Closed as not planned

Description

@vsfeedback

This issue has been moved from a ticket on Developer Community.


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.

Dada Huo [MSFT] on 11/3/2020, 00:38 AM:

Thank you for taking the time to log this issue! Did you still reproduce this issue in the latest stable version of Visual Studio installed from https://visualstudio.microsoft.com/downloads ?
If so, could you please provide a sample solution that has this problem so that we can conduct further research?

We look forward to hearing from you!

Full Name on 11/10/2020, 04:27 AM:

(private comment, text removed)


Original Solutions

(no solutions)

Activity

  1. added
    untriaged
    on Nov 13, 2020
  2. added and removed
    untriaged
    on Nov 16, 2020
  3. added this to the 6.0.0 milestone on Nov 16, 2020
  4. eiriktsarpalis commented on Nov 16, 2020

    @eiriktsarpalis
    Member

    The issue reproduces on Windows only (both in .NET Core and framework). Linux is unaffected.

  5. modified the milestones: 6.0.0, 7.0.0 on Jul 26, 2021
  6. modified the milestones: 7.0.0, Future on Jul 9, 2022
  7. added
    help wanted
    on Nov 13, 2023
  8. Neo-vortex commented on May 20, 2026

    @Neo-vortex
    Contributor

    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
    }

    @eiriktsarpalis, @adamsitnik If you think this is a good idea let me now and I will craete a PR for it

  9. adamsitnik commented on May 21, 2026

    @adamsitnik
    Member

    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.

  10. caraioniurie47 commented on Sep 13, 2026

    @caraioniurie47
    Contributor

    Summary

    • 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.
    • Separately, Console.ReadLine() returns each line one Enter late in this mode; filed as Console.ReadLine() returns each line one Enter late when Console.TreatControlCAsInput is true on 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.

    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.

  11. adamsitnik commented on Sep 14, 2026

    @adamsitnik
    Member

    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.

  12. locked and limited conversation to collaborators on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Consolebughelp wantedos-windows

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions