{"record":{"id":"712b016a30dfb933","repo":"tui-cs/Terminal.Gui","slug":"failed-to-paste-to-the-os-clipboard","errorCode":null,"errorMessage":"Failed to paste to the OS clipboard.","messagePattern":"Failed to paste to the OS clipboard\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"warning","filePath":"Terminal.Gui/App/Clipboard/ClipboardBase.cs","lineNumber":50,"sourceCode":"    }\n\n    /// <summary>Pastes the <paramref name=\"text\"/> to the OS clipboard if possible.</summary>\n    /// <param name=\"text\">The text to paste to the OS clipboard.</param>\n    /// <exception cref=\"NotSupportedException\">Thrown if it was not possible to paste to the OS clipboard.</exception>\n    public void SetClipboardData (string text)\n    {\n        if (text is null)\n        {\n            throw new ArgumentNullException (nameof (text));\n        }\n\n        try\n        {\n            SetClipboardDataImpl (text);\n        }\n        catch (NotSupportedException ex)\n        {\n            throw new NotSupportedException (\"Failed to paste to the OS clipboard.\", ex);\n        }\n    }\n\n    /// <summary>Copies the contents of the OS clipboard to <paramref name=\"result\"/> if possible.</summary>\n    /// <param name=\"result\">The contents of the OS clipboard if successful.</param>\n    /// <returns><see langword=\"true\"/> the OS clipboard was retrieved, <see langword=\"false\"/> otherwise.</returns>\n    public bool TryGetClipboardData (out string result)\n    {\n        result = string.Empty;\n\n        // Don't even try to read because environment is not set up.\n        if (!IsSupported)\n        {\n            return false;\n        }\n\n        try\n        {","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/App/Clipboard/ClipboardBase.cs#L32-L68","documentation":"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.","triggerScenarios":"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.","commonSituations":"Copy-to-clipboard features failing in headless deployments; Wayland sessions missing wl-copy; SSH sessions; CI environments.","solutions":["Guard writes with IsSupported before calling SetClipboardData, or use TrySetClipboardData if available.","Install the helper binary: apt-get install xclip (or wl-clipboard for Wayland: wl-copy/wl-paste).","Run in an interactive desktop session rather than redirected/headless.","Catch NotSupportedException and show a user-facing message that clipboard copy is unavailable."],"exampleFix":"// before\nApplication.Driver.Clipboard.SetClipboardData (text); // may throw\n\n// after\nif (Application.Driver?.Clipboard?.IsSupported == true)\n{\n    Application.Driver.Clipboard.SetClipboardData (text);\n}","handlingStrategy":"try-catch","validationCode":"if (Application.Driver?.Clipboard?.IsSupported == true)\n{\n    Application.Driver.Clipboard.SetClipboardData (text);\n}","typeGuard":"static bool ClipboardWritable () => Application.Driver?.Clipboard?.IsSupported == true;","tryCatchPattern":"try\n{\n    Application.Driver.Clipboard.SetClipboardData (text);\n}\ncatch (NotSupportedException ex)\n{\n    Logging.Warning ($\"Clipboard write unavailable: {ex.Message}\");\n}","preventionTips":["Check IsSupported before writing the clipboard.","Install the required helper (xclip/xsel/wl-copy) on Linux.","Degrade gracefully when clipboard is unavailable."],"tags":["clipboard","environment","platform","os"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}