{"record":{"id":"24c42bd779e4f826","repo":"tui-cs/Terminal.Gui","slug":"failed-to-set-output-console-mode-error-code-ge","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":"critical","filePath":"Terminal.Gui/Drivers/WindowsHelpers/NetWinVTConsole.cs","lineNumber":72,"sourceCode":"            }\n        }\n\n        _outputHandle = GetStdHandle (STD_OUTPUT_HANDLE);\n\n        if (!GetConsoleMode (_outputHandle, out mode))\n        {\n            throw new ApplicationException ($\"Failed to get output console mode, error code: {GetLastError ()}.\");\n        }\n\n        _originalOutputConsoleMode = mode;\n\n        if ((mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) == 0)\n        {\n            mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;\n\n            if (!SetConsoleMode (_outputHandle, mode))\n            {\n                throw new ApplicationException ($\"Failed to set output console mode, error code: {GetLastError ()}.\");\n            }\n        }\n    }\n\n    public void Cleanup ()\n    {\n        if (!FlushConsoleInputBuffer (_inputHandle))\n        {\n            throw new ApplicationException ($\"Failed to flush input queue, error code: {GetLastError ()}.\");\n        }\n\n        if (!SetConsoleMode (_inputHandle, _originalInputConsoleMode))\n        {\n            throw new ApplicationException ($\"Failed to restore input console mode, error code: {GetLastError ()}.\");\n        }\n\n        if (!SetConsoleMode (_outputHandle, _originalOutputConsoleMode))\n        {","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Drivers/WindowsHelpers/NetWinVTConsole.cs#L54-L90","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before -- default VT path fails on old Windows\nusing IApplication app = Application.Create().Init();\n\n// after -- select the legacy non-VT driver\nApplication.ForceDriver = \"Windows\";\nusing IApplication app = Application.Create().Init();","handlingStrategy":"validation","validationCode":"// Check VT processing support\nif (OperatingSystem.IsWindowsVersionAtLeast(10, 0, 16299)) { /* VT output supported */ }\nelse { Application.ForceDriver = \"Windows\"; }","typeGuard":null,"tryCatchPattern":"try { using IApplication app = Application.Create().Init(); app.Run<MyWindow>(); }\ncatch (ApplicationException ex) when (ex.Message.Contains(\"output console mode\") && ex.Message.Contains(\"Failed to set\"))\n{ Application.ForceDriver = \"Windows\"; /* retry with legacy non-VT driver */ }","preventionTips":["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."],"tags":["windows","console","driver","win32","output","initialization"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}