tui-cs/Terminal.Gui · critical · ApplicationException
Failed to set output console mode, error code: {GetLastError
Error message
Failed to set output console mode, error code: {GetLastError()}. What it means
This error is thrown by the NetWinVTConsole constructor when SetConsoleMode fails while attempting to enable ENABLE_VIRTUAL_TERMINAL_PROCESSING on the output handle. VT processing is required for the library to emit ANSI escape sequences for colors, line drawing, and cursor control. If the OS rejects the flag, the library cannot render the UI correctly via VT sequences.
Source
Thrown at Terminal.Gui/Drivers/WindowsHelpers/NetWinVTConsole.cs:72
}
}
_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))
{
throw new ApplicationException ($"Failed to set output console mode, error code: {GetLastError ()}.");
}
}
}
public void Cleanup ()
{
if (!FlushConsoleInputBuffer (_inputHandle))
{
throw new ApplicationException ($"Failed to flush input queue, error code: {GetLastError ()}.");
}
if (!SetConsoleMode (_inputHandle, _originalInputConsoleMode))
{
throw new ApplicationException ($"Failed to restore input console mode, error code: {GetLastError ()}.");
}
if (!SetConsoleMode (_outputHandle, _originalOutputConsoleMode))
{View on GitHub (pinned to 2e47b11478)
Solutions
- Upgrade to Windows 10+ or apply the relevant update that enables VT processing.
- Use the legacy WindowsDriver (non-VT) which renders via the console API directly rather than ANSI sequences.
- If in a locked-down environment, check registry key HKCU\Console\ForceV2 and ensure it is not disabled.
- Verify the console host supports VT (Windows Terminal and modern conhost do).
Example fix
// before -- default VT path fails on old Windows using IApplication app = Application.Create().Init(); // after -- select the legacy non-VT driver Application.ForceDriver = "Windows"; using IApplication app = Application.Create().Init();
Defensive patterns
Strategy: validation
Validate before calling
// Check VT processing support
if (OperatingSystem.IsWindowsVersionAtLeast(10, 0, 16299)) { /* VT output supported */ }
else { Application.ForceDriver = "Windows"; } Try / catch
try { using IApplication app = Application.Create().Init(); app.Run<MyWindow>(); }
catch (ApplicationException ex) when (ex.Message.Contains("output console mode") && ex.Message.Contains("Failed to set"))
{ Application.ForceDriver = "Windows"; /* retry with legacy non-VT driver */ } Prevention
- Upgrade to Windows 10+ for ENABLE_VIRTUAL_TERMINAL_PROCESSING support.
- Force the legacy WindowsDriver on older Windows via Application.ForceDriver = "Windows".
- Check that the console host supports VT (Windows Terminal, modern conhost).
- Verify HKCU Console ForceV2 registry setting is not disabling VT.
When it happens
Trigger: Thrown at NetWinVTConsole.cs:72 when (mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) == 0 and the subsequent SetConsoleMode(_outputHandle, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING) returns false. Only triggers on Windows versions or console hosts that do not support VT processing.
Common situations: Running on Windows versions prior to 10 (Windows 7/8), running on Windows Server Core editions without the VT-processing update, using a third-party console replacement that does not implement VT, or group policy / registry settings disabling VT output.
Related errors
- Failed to get output console mode, error code: {GetLastError
- Failed to set screenBuffer console mode, error code: {Marsha
- Failed to get input console mode, error code: {GetLastError(
- Failed to set input console mode, error code: {GetLastError(
- Failed to set output console mode, error code: {GetLastError
AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13).
Data as JSON: /api/errors/24c42bd779e4f826.
Report an issue: GitHub.