tui-cs/Terminal.Gui · warning · NotSupportedException

Failed to copy from the OS clipboard.

Error message

Failed to copy from the OS clipboard.

What it means

Thrown by ClipboardBase.GetClipboardData when the platform-specific GetClipboardDataImpl throws NotSupportedException. The wrapper re-throws a new NotSupportedException with a friendlier message, preserving the original as InnerException. This typically means the OS clipboard helper (xclip/xsel/pbcopy/wl-paste, or the Windows clipboard API) is unavailable or the environment does not support clipboard access.

Source

Thrown at Terminal.Gui/App/Clipboard/ClipboardBase.cs:30

    /// <summary>Returns the contents of the OS clipboard if possible.</summary>
    /// <returns>The contents of the OS clipboard if successful.</returns>
    /// <exception cref="NotSupportedException">Thrown if it was not possible to copy from the OS clipboard.</exception>
    public string GetClipboardData ()
    {
        try
        {
            string result = GetClipboardDataImpl ();

            if (result is null)
            {
                return string.Empty;
            }

            return result;
        }
        catch (NotSupportedException ex)
        {
            throw new NotSupportedException ("Failed to copy from the OS clipboard.", ex);
        }
    }

    /// <summary>Pastes the <paramref name="text"/> to the OS clipboard if possible.</summary>
    /// <param name="text">The text to paste to the OS clipboard.</param>
    /// <exception cref="NotSupportedException">Thrown if it was not possible to paste to the OS clipboard.</exception>
    public void SetClipboardData (string text)
    {
        if (text is null)
        {
            throw new ArgumentNullException (nameof (text));
        }

        try
        {
            SetClipboardDataImpl (text);
        }
        catch (NotSupportedException ex)

View on GitHub (pinned to 2e47b11478)

Solutions

  1. Before reading, check Application.Driver?.Clipboard?.IsSupported and use TryGetClipboardData which returns false instead of throwing.
  2. Install the required clipboard helper on Linux: apt-get install xclip (or xsel, or wl-clipboard for Wayland).
  3. Run in an environment with a real clipboard (interactive desktop session) rather than headless/redirected.
  4. Catch NotSupportedException and degrade gracefully (e.g. disable paste functionality).

Example fix

// before
string text = Application.Driver.Clipboard.GetClipboardData (); // may throw

// after
if (Application.Driver?.Clipboard?.IsSupported == true)
{
    string text = Application.Driver.Clipboard.GetClipboardData ();
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (Application.Driver?.Clipboard?.IsSupported == true)
{
    string text = Application.Driver.Clipboard.GetClipboardData ();
}

Type guard

static bool ClipboardAvailable () => Application.Driver?.Clipboard?.IsSupported == true;

Try / catch

try
{
    string text = Application.Driver.Clipboard.GetClipboardData ();
}
catch (NotSupportedException ex)
{
    Logging.Warning ($"Clipboard read unavailable: {ex.Message}");
    text = string.Empty;
}

Prevention

When it happens

Trigger: Reading the clipboard on a headless Linux without xclip/xsel/wl-paste installed; running over SSH without clipboard forwarding; a CI/container environment with no clipboard daemon; the terminal redirecting input/output (ClipboardProcessRunner bails early in that case).

Common situations: Headless servers, Docker containers, SSH sessions, CI pipelines; Linux distros missing the clipboard helper binaries; Wayland vs X11 mismatches where the wrong helper is invoked.

Related errors


AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13). Data as JSON: /api/errors/650ae8466e902ffd. Report an issue: GitHub.