{"record":{"id":"650ae8466e902ffd","repo":"tui-cs/Terminal.Gui","slug":"failed-to-copy-from-the-os-clipboard","errorCode":null,"errorMessage":"Failed to copy from the OS clipboard.","messagePattern":"Failed to copy from the OS clipboard\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"warning","filePath":"Terminal.Gui/App/Clipboard/ClipboardBase.cs","lineNumber":30,"sourceCode":"    /// <summary>Returns the contents of the OS clipboard if possible.</summary>\n    /// <returns>The contents of the OS clipboard if successful.</returns>\n    /// <exception cref=\"NotSupportedException\">Thrown if it was not possible to copy from the OS clipboard.</exception>\n    public string GetClipboardData ()\n    {\n        try\n        {\n            string result = GetClipboardDataImpl ();\n\n            if (result is null)\n            {\n                return string.Empty;\n            }\n\n            return result;\n        }\n        catch (NotSupportedException ex)\n        {\n            throw new NotSupportedException (\"Failed to copy from the OS clipboard.\", ex);\n        }\n    }\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)","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/App/Clipboard/ClipboardBase.cs#L12-L48","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Before reading, check Application.Driver?.Clipboard?.IsSupported and use TryGetClipboardData which returns false instead of throwing.","Install the required clipboard helper on Linux: apt-get install xclip (or xsel, or wl-clipboard for Wayland).","Run in an environment with a real clipboard (interactive desktop session) rather than headless/redirected.","Catch NotSupportedException and degrade gracefully (e.g. disable paste functionality)."],"exampleFix":"// before\nstring text = Application.Driver.Clipboard.GetClipboardData (); // may throw\n\n// after\nif (Application.Driver?.Clipboard?.IsSupported == true)\n{\n    string text = Application.Driver.Clipboard.GetClipboardData ();\n}","handlingStrategy":"try-catch","validationCode":"if (Application.Driver?.Clipboard?.IsSupported == true)\n{\n    string text = Application.Driver.Clipboard.GetClipboardData ();\n}","typeGuard":"static bool ClipboardAvailable () => Application.Driver?.Clipboard?.IsSupported == true;","tryCatchPattern":"try\n{\n    string text = Application.Driver.Clipboard.GetClipboardData ();\n}\ncatch (NotSupportedException ex)\n{\n    Logging.Warning ($\"Clipboard read unavailable: {ex.Message}\");\n    text = string.Empty;\n}","preventionTips":["Check IsSupported before reading the clipboard.","Prefer TryGetClipboardData which returns false instead of throwing.","Ensure xclip/xsel/wl-paste is installed on Linux."],"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"}