tui-cs/Terminal.Gui · critical · ApplicationException

Failed to set input console mode, error code: {GetLastError(

Error message

Failed to set input console mode, error code: {GetLastError()}.

What it means

This error is thrown by the NetWinVTConsole constructor when SetConsoleMode fails while attempting to add ENABLE_VIRTUAL_TERMINAL_INPUT to the input console mode. This happens when the current input mode does not already have VT input enabled and the OS rejects the attempt to enable it. The GetLastError code indicates why the OS refused.

Source

Thrown at Terminal.Gui/Drivers/WindowsHelpers/NetWinVTConsole.cs:53

    public NetWinVTConsole ()
    {
        _inputHandle = GetStdHandle (STD_INPUT_HANDLE);

        if (!GetConsoleMode (_inputHandle, out uint mode))
        {
            throw new ApplicationException ($"Failed to get input console mode, error code: {GetLastError ()}.");
        }

        _originalInputConsoleMode = mode;

        if ((mode & ENABLE_VIRTUAL_TERMINAL_INPUT) == 0)
        {
            mode |= ENABLE_VIRTUAL_TERMINAL_INPUT;

            if (!SetConsoleMode (_inputHandle, mode))
            {
                throw new ApplicationException ($"Failed to set input console mode, error code: {GetLastError ()}.");
            }
        }

        _outputHandle = GetStdHandle (STD_OUTPUT_HANDLE);

        if (!GetConsoleMode (_outputHandle, out mode))
        {
            throw new ApplicationException ($"Failed to get output console mode, error code: {GetLastError ()}.");
        }

        _originalOutputConsoleMode = mode;

        if ((mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) == 0)
        {
            mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;

            if (!SetConsoleMode (_outputHandle, mode))
            {

View on GitHub (pinned to 2e47b11478)

Solutions

  1. Upgrade to Windows 10 version 1709 or later where ENABLE_VIRTUAL_TERMINAL_INPUT is natively supported.
  2. Check for terminal-interception software (e.g., wrapper tools) and disable them.
  3. If on an older system, select the legacy WindowsDriver input path (non-VT) instead of the VT helper.
  4. Verify the console host is conhost.exe / Windows Terminal and not a custom replacement that does not support the VT input flag.

Example fix

// before -- default driver selection hits VT input on unsupported OS
using IApplication app = Application.Create().Init();

// after -- force the legacy Windows driver on older Windows
Application.ForceDriver = "Windows";
using IApplication app = Application.Create().Init();
Defensive patterns

Strategy: validation

Validate before calling

// Check Windows version supports VT input
if (OperatingSystem.IsWindowsVersionAtLeast(10, 0, 16299)) { /* VT input supported */ }
else { Application.ForceDriver = "Windows"; /* use legacy driver */ }

Try / catch

try { using IApplication app = Application.Create().Init(); app.Run<MyWindow>(); }
catch (ApplicationException ex) when (ex.Message.Contains("set input console mode"))
{ Application.ForceDriver = "Windows"; /* retry with legacy */ }

Prevention

When it happens

Trigger: Thrown at NetWinVTConsole.cs:53 when (mode & ENABLE_VIRTUAL_TERMINAL_INPUT) == 0 and the subsequent SetConsoleMode(_inputHandle, mode | ENABLE_VIRTUAL_TERMINAL_INPUT) returns false. This is a Windows 10+ feature; older OS versions or locked-down consoles reject the flag.

Common situations: Running on Windows versions prior to 1709 (Threshold 2 / pre-Anniversary Update), running under a locked-down kiosk or restricted console session, third-party terminal interceptors that wrap the console handle, or group policy disabling VT input.

Related errors


AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13). Data as JSON: /api/errors/236802a817e16b08. Report an issue: GitHub.