{"record":{"id":"2f7154148a2523d8","repo":"tui-cs/Terminal.Gui","slug":"failed-to-set-output-console-mode-error-code-ge-2f7154","errorCode":null,"errorMessage":"Failed to set output console mode, error code: {GetLastError()}.","messagePattern":"Failed to set output console mode, error code: (.+?)\\.","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"warning","filePath":"Terminal.Gui/Drivers/WindowsHelpers/WindowsVTOutputHelper.cs","lineNumber":107,"sourceCode":"                return false;\n            }\n\n            if (!GetConsoleMode (OutputHandle, out _originalConsoleMode))\n            {\n                Logging.Warning (\"Failed to get Windows console mode.\");\n\n                return false;\n            }\n\n            uint newMode = _originalConsoleMode;\n\n            if ((newMode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) == 0)\n            {\n                newMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;\n\n                if (!SetConsoleMode (OutputHandle, newMode))\n                {\n                    throw new ApplicationException ($\"Failed to set output console mode, error code: {GetLastError ()}.\");\n                }\n            }\n\n            if ((newMode & ENABLE_PROCESSED_OUTPUT) == 0)\n            {\n                newMode |= ENABLE_PROCESSED_OUTPUT;\n\n                if (!SetConsoleMode (OutputHandle, newMode))\n                {\n                    throw new ApplicationException ($\"Failed to set output console mode, error code: {GetLastError ()}.\");\n                }\n            }\n\n            IsEnabled = true;\n\n            //Logging.Information ($\"Windows VTS output mode enabled successfully. Mode: 0x{newMode:X} (was 0x{_originalConsoleMode:X})\");\n\n            return true;","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Drivers/WindowsHelpers/WindowsVTOutputHelper.cs#L89-L125","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":"// before -- relying on VT, which silently fails on old consoles\nusing IApplication app = Application.Create().Init();\n\n// after -- check logs; force legacy driver if VT is unsupported\nApplication.ForceDriver = \"Windows\";\nusing IApplication app = Application.Create().Init();","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"// TryEnable already catches this internally and returns false;\n// check the return value or logs\nif (!windowsVTOutputHelper.TryEnable())\n{ Logging.Warning(\"VT output could not be enabled; falling back to legacy rendering.\"); }","preventionTips":["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."],"tags":["windows","console","driver","win32","output"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}