felixse/FluentTerminal · critical · Win32Exception
Could not enable virtual terminal processing.
Error message
Could not enable virtual terminal processing.
What it means
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.
Source
Thrown at FluentTerminal.SystemTray/Services/ConPty/Terminal.cs:78
}
~Terminal()
{
Dispose(false);
}
private void EnableVirtualTerminalSequenceProcessing()
{
SafeFileHandle screenBuffer = GetConsoleScreenBuffer();
if (!GetConsoleMode(screenBuffer, out uint outConsoleMode))
{
throw new Win32Exception(Marshal.GetLastWin32Error(), $"Could not get console mode.");
}
outConsoleMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN;
if (!SetConsoleMode(screenBuffer, outConsoleMode))
{
throw new Win32Exception(Marshal.GetLastWin32Error(), $"Could not enable virtual terminal processing.");
}
}
/// <summary>
/// Start the psuedoconsole and run the process as shown in
/// https://docs.microsoft.com/en-us/windows/console/creating-a-pseudoconsole-session#creating-the-pseudoconsole
/// </summary>
/// <param name="command">the command to run, e.g. cmd.exe</param>
/// <param name="consoleHeight">The height (in characters) to start the pseudoconsole with. Defaults to 80.</param>
/// <param name="consoleWidth">The width (in characters) to start the pseudoconsole with. Defaults to 30.</param>
public void Start(string command, string directory, string environment, int consoleWidth = 80, int consoleHeight = 30)
{
_inputPipe = new PseudoConsolePipe();
_outputPipe = new PseudoConsolePipe();
_pseudoConsole = PseudoConsole.Create(_inputPipe.ReadSide, _outputPipe.WriteSide, consoleWidth, consoleHeight);
_process = ProcessFactory.Start(command, directory, environment, PseudoConsole.PseudoConsoleThreadAttribute, _pseudoConsole.Handle);
View on GitHub (pinned to ba83ec485e)
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.
Example fix
// before
if (!SetConsoleMode(screenBuffer, outConsoleMode))
throw new Win32Exception(Marshal.GetLastWin32Error(), $"Could not enable virtual terminal processing.");
// after - report the native error code
int err = Marshal.GetLastWin32Error();
throw new Win32Exception(err, $"Could not enable virtual terminal processing (Win32 error {err}). VT support requires Windows 10 1607+."); Defensive patterns
Strategy: try-catch
Validate before calling
// Feature-detect VT processing support.
GetConsoleMode(screenBuffer, out uint mode);
if ((mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) == 0 && !SetConsoleMode(screenBuffer, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING))
throw new PlatformNotSupportedException("VT processing requires Windows 10 1607+."); Try / catch
try { terminal = new Terminal(); }
catch (System.ComponentModel.Win32Exception ex) when (ex.Message.Contains("virtual terminal")) { logger.Error(ex, $"SetConsoleMode failed (Win32 {ex.NativeErrorCode})"); fallbackToWinPty(); } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Could not allocate console for this process.
- Could not get console mode.
- Could not get console screen buffer.
- failed to create pipe
- winpty_error_msg(errorHandle)
AI-assisted analysis of felixse/FluentTerminal@ba83ec485e (2026-08-13).
Data as JSON: /api/errors/ac440ba4f7c6bdf7.
Report an issue: GitHub.