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
- Upgrade to Windows 10 version 1709 or later where ENABLE_VIRTUAL_TERMINAL_INPUT is natively supported.
- Check for terminal-interception software (e.g., wrapper tools) and disable them.
- If on an older system, select the legacy WindowsDriver input path (non-VT) instead of the VT helper.
- 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
- Upgrade to Windows 10 1709+ for ENABLE_VIRTUAL_TERMINAL_INPUT support.
- Force the legacy WindowsDriver on older Windows via Application.ForceDriver = "Windows".
- Disable third-party console interceptors that may block VT input.
- Check for group policy disabling VT input features.
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
- Failed to get input console mode, error code: {GetLastError(
- Failed to set screenBuffer console mode, error code: {Marsha
- Failed to get output console mode, error code: {GetLastError
- Failed to set output console mode, error code: {GetLastError
- Failed to get screenBuffer console mode, error code: {Marsha
AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13).
Data as JSON: /api/errors/236802a817e16b08.
Report an issue: GitHub.