Skip to content

Clipboard.ContainsText behaves differently in .NET8 .NET9 .NET10 #14172

Open

Description

@a-solovyev-dx

.NET version

net8.0-windows
net9.0-windows
net10.0-windows

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

net8.0-windows

Issue description

The following code displays "Nothing" in .net9. Both .net8 and .net10 display "Something"

DataObject data = new DataObject();
data.SetData("Something");
Clipboard.SetDataObject(data);

if(Clipboard.ContainsText())
    MessageBox.Show(this, Clipboard.GetText());
else
    MessageBox.Show(this, "Nothing");

.net8

Image

.net9

Image

.net10

Image

Steps to reproduce

WinFormsApp2.zip
You may use this project as a reference

Activity

  1. added
    untriaged
    on Dec 26, 2025
  2. added
    area-Clipboard
    on Dec 26, 2025
  3. Zheng-Li01 commented on Dec 29, 2025

    @Zheng-Li01
    Member

    @a-solovyev-dx, thanks raised the issue, the issue have been reported than before, and have been resolved, please see details in #12665.
    And the fix should also be port in .NET 9.0 but seems there have some wrong things appear, will investigate it,

  4. Zheng-Li01 commented on Jan 4, 2026

    @Zheng-Li01
    Member

    Seems related the issue #12789

  5. LeafShi1 commented on Jan 4, 2026

    @LeafShi1
    Member

    The behavioral change in .NET 9.0 originated from PR #10651.

    PR #12833 (which updated ContainsText to pass autoConvert: true:

    return ContainsData(ConvertToDataFormats(format), autoConvert: true);
    )
    resolved this regression in .NET 10.0, restoring the behavior to match .NET 8.0.

    @merriemcgaw @KlausLoeffelmann — should we consider backporting this fix to .NET 9.0 as well?

  6. added
    waiting-on-team
    and removed
    untriaged
    on Jan 5, 2026
  7. merriemcgaw commented on Jan 6, 2026

    @merriemcgaw
    Contributor

    @a-solovyev-dx is this blocking your application in some way? .NET 9 will be supported for most of this year, but you're better off generally going with the LTS of .NET 10 which will last until Nov 2028. If you're blocked and can't move to 10, we can consider servicing.

  8. KlausLoeffelmann commented on Jan 7, 2026

    @KlausLoeffelmann
    Member

    The behavioral change in .NET 9.0 originated from PR #10651.

    PR #12833 (which updated ContainsText to pass autoConvert: true:

    winforms/src/System.Windows.Forms/System/Windows/Forms/OLE/Clipboard.cs

    Line 127 in 05b7c2e

    return ContainsData(ConvertToDataFormats(format), autoConvert: true);
    )
    resolved this regression in .NET 10.0, restoring the behavior to match .NET 8.0.
    @merriemcgaw @KlausLoeffelmann — should we consider backporting this fix to .NET 9.0 as well?

    What @merriemcgaw said.

  9. a-solovyev-dx commented on Jan 8, 2026

    @a-solovyev-dx
    Author

    @a-solovyev-dx is this blocking your application in some way? .NET 9 will be supported for most of this year, but you're better off generally going with the LTS of .NET 10 which will last until Nov 2028. If you're blocked and can't move to 10, we can consider servicing.

    We are not building end-user applications, but rather provide components for our clients to build upon. With this in mind we cannot guarantee they all move to .NET 10. In fact, this issue was discovered by one of our clients and we had to think about some workaround for them.

  10. LeafShi1 commented on Jan 9, 2026

    @LeafShi1
    Member

    As a workaround:
    Users can change the way the clipboard is set to SetText, which will store the text in the correct text format (UnicodeText).
    Clipboard.SetText("Something");
    If a DataObject must be used, the text can be explicitly placed into the DataObject in UnicodeText format.
    data.SetData(DataFormats.UnicodeText, "Something");

  11. a-solovyev-dx commented on Jan 9, 2026

    @a-solovyev-dx
    Author

    Thank you for the workaround. However, in our case, the logic of the clipboard is hidden from the user sometimes (i.e. built-in context menus, commands, etc) and in some cases we cannot even guarantee that there will be text and not something else due to the nature of the data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Clipboardwaiting-on-team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions