tui-cs/Terminal.Gui · warning · 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 WindowsVTOutputHelper.TryEnable() when SetConsoleMode fails while adding ENABLE_VIRTUAL_TERMINAL_PROCESSING to the output handle. Unlike NetWinVTConsole, TryEnable is designed to be fault-tolerant -- the thrown ApplicationException is immediately caught by the surrounding try/catch (WindowsVTOutputHelper.cs:127) and converted to a logged warning returning false. The user normally sees only a warning, not the exception, unless examining logs.
Source
Thrown at Terminal.Gui/Drivers/WindowsHelpers/WindowsVTOutputHelper.cs:107
return false;
}
if (!GetConsoleMode (OutputHandle, out _originalConsoleMode))
{
Logging.Warning ("Failed to get Windows console mode.");
return false;
}
uint newMode = _originalConsoleMode;
if ((newMode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) == 0)
{
newMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
if (!SetConsoleMode (OutputHandle, newMode))
{
throw new ApplicationException ($"Failed to set output console mode, error code: {GetLastError ()}.");
}
}
if ((newMode & ENABLE_PROCESSED_OUTPUT) == 0)
{
newMode |= ENABLE_PROCESSED_OUTPUT;
if (!SetConsoleMode (OutputHandle, newMode))
{
throw new ApplicationException ($"Failed to set output console mode, error code: {GetLastError ()}.");
}
}
IsEnabled = true;
//Logging.Information ($"Windows VTS output mode enabled successfully. Mode: 0x{newMode:X} (was 0x{_originalConsoleMode:X})");
return true;View on GitHub (pinned to 2e47b11478)
Solutions
- Check the application log for the warning 'Failed to enable Windows VTS mode' -- the underlying Win32 error code is in the exception message.
- Upgrade the Windows version or console host to one supporting VT processing.
- If VT is unavailable, select the legacy WindowsDriver via Application.ForceDriver = "Windows".
- Since TryEnable already catches and logs this, usually no action is needed unless VT rendering was expected -- investigate the Win32 error code.
Example fix
// before -- relying on VT, which silently fails on old consoles using IApplication app = Application.Create().Init(); // after -- check logs; force legacy driver if VT is unsupported Application.ForceDriver = "Windows"; using IApplication app = Application.Create().Init();
Defensive patterns
Strategy: fallback
Try / catch
// TryEnable already catches this internally and returns false;
// check the return value or logs
if (!windowsVTOutputHelper.TryEnable())
{ Logging.Warning("VT output could not be enabled; falling back to legacy rendering."); } Prevention
- Monitor application logs for 'Failed to enable Windows VTS mode' warnings.
- Upgrade Windows to a version supporting VT processing.
- Force the legacy WindowsDriver if VT is unavailable.
- Note that TryEnable already handles this gracefully -- usually no action needed.
When it happens
Trigger: Thrown at WindowsVTOutputHelper.cs:107 when (newMode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) == 0 and SetConsoleMode(OutputHandle, newMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING) returns false. The OutputHandle is obtained from TerminalDevice.OutputHandle (CONOUT$). Because TryEnable wraps this in try/catch, the exception is caught and TryEnable returns false.
Common situations: Running on a Windows version or console host without VT processing support, the output handle being invalid despite being non-zero, or the console being in a restricted mode. The user-facing symptom is a logged warning 'Failed to enable Windows VTS mode' and VT rendering being disabled (falling back to legacy rendering).
Related errors
- 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
- Failed to set screenBuffer console mode, error code: {Marsha
- Failed to get input console mode, error code: {GetLastError(
AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13).
Data as JSON: /api/errors/2f7154148a2523d8.
Report an issue: GitHub.