tui-cs/Terminal.Gui · warning · NotSupportedException

Failed to paste to the OS clipboard.

Error message

Failed to paste to the OS clipboard.

What it means

Thrown by ClipboardBase.SetClipboardData when the platform-specific SetClipboardDataImpl throws NotSupportedException, re-wrapped with a clearer message and the original as InnerException. It indicates the OS clipboard write path is unavailable — missing helper binary, headless/SSH environment, or redirected console.

Source

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

    }

    /// <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)
        {
            throw new NotSupportedException ("Failed to paste to the OS clipboard.", ex);
        }
    }

    /// <summary>Copies the contents of the OS clipboard to <paramref name="result"/> if possible.</summary>
    /// <param name="result">The contents of the OS clipboard if successful.</param>
    /// <returns><see langword="true"/> the OS clipboard was retrieved, <see langword="false"/> otherwise.</returns>
    public bool TryGetClipboardData (out string result)
    {
        result = string.Empty;

        // Don't even try to read because environment is not set up.
        if (!IsSupported)
        {
            return false;
        }

        try
        {

View on GitHub (pinned to 2e47b11478)

Solutions

  1. Guard writes with IsSupported before calling SetClipboardData, or use TrySetClipboardData if available.
  2. Install the helper binary: apt-get install xclip (or wl-clipboard for Wayland: wl-copy/wl-paste).
  3. Run in an interactive desktop session rather than redirected/headless.
  4. Catch NotSupportedException and show a user-facing message that clipboard copy is unavailable.

Example fix

// before
Application.Driver.Clipboard.SetClipboardData (text); // may throw

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

Strategy: try-catch

Validate before calling

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

Type guard

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

Try / catch

try
{
    Application.Driver.Clipboard.SetClipboardData (text);
}
catch (NotSupportedException ex)
{
    Logging.Warning ($"Clipboard write unavailable: {ex.Message}");
}

Prevention

When it happens

Trigger: Writing to the clipboard on Linux without xclip/xsel/wl-copy installed; over SSH without clipboard forwarding; in a container or CI without a clipboard daemon; Console.IsInputRedirected/IsOutputRedirected causing the helper process to bail.

Common situations: Copy-to-clipboard features failing in headless deployments; Wayland sessions missing wl-copy; SSH sessions; CI environments.

Related errors


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