{"record":{"id":"ac440ba4f7c6bdf7","repo":"felixse/FluentTerminal","slug":"could-not-enable-virtual-terminal-processing","errorCode":null,"errorMessage":"Could not enable virtual terminal processing.","messagePattern":"Could not enable virtual terminal processing\\.","errorType":"exception","errorClass":"Win32Exception","httpStatus":null,"severity":"critical","filePath":"FluentTerminal.SystemTray/Services/ConPty/Terminal.cs","lineNumber":78,"sourceCode":"        }\n\n        ~Terminal()\n        {\n            Dispose(false);\n        }\n\n        private void EnableVirtualTerminalSequenceProcessing()\n        {\n            SafeFileHandle screenBuffer = GetConsoleScreenBuffer();\n            if (!GetConsoleMode(screenBuffer, out uint outConsoleMode))\n            {\n                throw new Win32Exception(Marshal.GetLastWin32Error(), $\"Could not get console mode.\");\n            }\n            outConsoleMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN;\n\n            if (!SetConsoleMode(screenBuffer, outConsoleMode))\n            {\n                throw new Win32Exception(Marshal.GetLastWin32Error(), $\"Could not enable virtual terminal processing.\");\n            }\n        }\n\n        /// <summary>\n        /// Start the psuedoconsole and run the process as shown in \n        /// https://docs.microsoft.com/en-us/windows/console/creating-a-pseudoconsole-session#creating-the-pseudoconsole\n        /// </summary>\n        /// <param name=\"command\">the command to run, e.g. cmd.exe</param>\n        /// <param name=\"consoleHeight\">The height (in characters) to start the pseudoconsole with. Defaults to 80.</param>\n        /// <param name=\"consoleWidth\">The width (in characters) to start the pseudoconsole with. Defaults to 30.</param>\n        public void Start(string command, string directory, string environment, int consoleWidth = 80, int consoleHeight = 30)\n        {\n            _inputPipe = new PseudoConsolePipe();\n            _outputPipe = new PseudoConsolePipe();\n            _pseudoConsole = PseudoConsole.Create(_inputPipe.ReadSide, _outputPipe.WriteSide, consoleWidth, consoleHeight);\n\n            _process = ProcessFactory.Start(command, directory, environment, PseudoConsole.PseudoConsoleThreadAttribute, _pseudoConsole.Handle);\n","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/felixse/FluentTerminal/blob/ba83ec485eea8d8ee65825711731300bee2e76ed/FluentTerminal.SystemTray/Services/ConPty/Terminal.cs#L60-L96","documentation":"Thrown by Terminal.EnableVirtualTerminalSequenceProcessing when SetConsoleMode() fails after OR-ing in ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN. The pseudoconsole output relies on VT sequence processing; if the mode cannot be set, terminal rendering cannot proceed and the Win32 error is thrown.","triggerScenarios":"SetConsoleMode returns false, most commonly because ENABLE_VIRTUAL_TERMINAL_PROCESSING is unsupported on the running Windows build (it requires Windows 10 1607+/desktop). The flag is silently dropped or rejected on older/console-host setups.","commonSituations":"Running on a Windows build older than 1607, or in a session whose console driver does not support VT processing; the screen-buffer handle is invalid.","solutions":["Upgrade to Windows 10 1607 (Anniversary Update) or later; ConPty overall needs 1809+.","Verify the screen-buffer handle is valid before SetConsoleMode (see error 14).","Check Win32Exception.NativeErrorCode to distinguish unsupported-feature from invalid-handle.","Switch the profile/backend to WinPty if ConPty is unavailable on this OS."],"exampleFix":"// before\nif (!SetConsoleMode(screenBuffer, outConsoleMode))\n    throw new Win32Exception(Marshal.GetLastWin32Error(), $\"Could not enable virtual terminal processing.\");\n\n// after - report the native error code\nint err = Marshal.GetLastWin32Error();\nthrow new Win32Exception(err, $\"Could not enable virtual terminal processing (Win32 error {err}). VT support requires Windows 10 1607+.\");","handlingStrategy":"try-catch","validationCode":"// Feature-detect VT processing support.\nGetConsoleMode(screenBuffer, out uint mode);\nif ((mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) == 0 && !SetConsoleMode(screenBuffer, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING))\n    throw new PlatformNotSupportedException(\"VT processing requires Windows 10 1607+.\");","typeGuard":null,"tryCatchPattern":"try { terminal = new Terminal(); }\ncatch (System.ComponentModel.Win32Exception ex) when (ex.Message.Contains(\"virtual terminal\")) { logger.Error(ex, $\"SetConsoleMode failed (Win32 {ex.NativeErrorCode})\"); fallbackToWinPty(); }","preventionTips":["Require Windows 10 1607+ (ConPty needs 1809+) for the ConPty backend.","Check NativeErrorCode to distinguish unsupported-feature from invalid-handle.","Provide a WinPty fallback for older builds."],"tags":["conpty","win32","console","vt-processing","native","terminal-backend"],"backgroundTag":null,"analyzedSha":"ba83ec485eea8d8ee65825711731300bee2e76ed","analyzedAt":"2026-08-13T21:23:15.467Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}