Skip to content

Regression: Clipboard.GetText() returns empty string or corrupted text (mojibake) randomly in .NET 10 #14322

Closed

Description

@rampaa

Description

After migrating an application to .NET 10, Clipboard.GetText() sometimes returns corrupted text or an empty string when reading Unicode (e.g., Japanese) content from the Windows clipboard. This behavior did not occur prior to .NET 10.

Example of corrupted output:

Expected:
「うわ、ほんとだ……あれ、どれくらいの高さなんだろ」
Actual:
????????・????????????????
or:
"" (Length = 0)

The issue appears intermittently and is difficult to reproduce deterministically, but becomes noticeable under frequent clipboard updates. Note that using Clipboard.ContainsText(TextDataFormat.UnicodeText) and Clipboard.GetText(TextDataFormat.UnicodeText) has the exact same problem.

Reproduction Steps

  1. Create a WPF application targeting .NET 10.
  2. Monitor clipboard changes using WM_CLIPBOARDUPDATE.
  3. On clipboard updates, call Clipboard.GetText() to retrieve text contents.
  4. Frequently copy Unicode text to Clipboard

Minimal example:

if (Clipboard.ContainsText()) // You can also use Clipboard.ContainsText(TextDataFormat.UnicodeText)
{
// Occasionally returns empty string or mojibake
string text = Clipboard.GetText(); // Clipboard.GetText(TextDataFormat.UnicodeText)
}

Intermittently, the returned string is either empty (this is more common) or contains corrupted characters instead of the original Unicode text (this is rarer).

Expected behavior

Expected behavior

Clipboard.GetText() should consistently return the correct Unicode text as placed on the clipboard, or throw a managed exception if the clipboard data is temporarily unavailable.

It should never silently return corrupted text or an empty string when valid Unicode text exists.

Actual behavior

Clipboard.GetText() intermittently returns:

  1. An empty string (Length == 0)
  2. Or a string containing mojibake (e.g., ?, ・), or

No exception is thrown in these cases.

Regression?

Yes.

Yes. This code path worked reliably in previous .NET versions. I never had a problem with .NET 5, .NET 6, .NET 7, .NET 8, .NET 9.

Known Workarounds

No response

Impact

No response

Configuration

No response

Other information

No response

Activity

  1. rampaa commented on Jan 29, 2026

    @rampaa
    Author

    Possibly caused by dotnet/wpf#10544

  2. JeremyKuhne commented on Jan 30, 2026

    @JeremyKuhne
    Member

    I'm pretty sure I know what is causing this. We weren't properly checking the result of GetData after QueryHasData. Working with the WinForms team to try and get this serviced.

  3. JeremyKuhne commented on Jan 30, 2026

    @JeremyKuhne
    Member

    I've put up a PR in WinForms main that @Shyam-Gupta is going to take further to vet that it fixes your issue and get it through our servicing process.

  4. rampaa commented on Feb 21, 2026

    @rampaa
    Author

    @merriemcgaw @Shyam-Gupta

    Does this issue need to be transferred to the WinForms repo (like #14308) in order for it to be backported to .NET 10?

  5. transferred this issue fromdotnet/wpfon Feb 23, 2026
  6. added
    area-Clipboard
    on Feb 23, 2026
  7. Shyam-Gupta commented on Feb 23, 2026

    @Shyam-Gupta
    Member

    @rampaa I have transferred the issue to WinForms repo. Thanks.

  8. self-assigned this
    on Feb 23, 2026
  9. rampaa commented on Apr 14, 2026

    @rampaa
    Author

    Thanks @Shyam-Gupta! Does this issue need to be tagged as 💥 regression-release, since the issue did not occur in .NET 9? FWIW this issue is a hard blocker on .NET 10 migration for me.

  10. SimonZhao888 commented on Apr 23, 2026

    @SimonZhao888
    Member

    A race read occurring while reading the clipboard content may be the cause of this issue.

  11. rampaa commented on May 29, 2026

    @rampaa
    Author

    Any chance this issue could be tagged with 💥 regression-release as it is a .NET 10 regression? I had to revert one of my projects to .NET 9 because of this bug, and .NET 9’s end-of-support date is November 10, 2026.

  12. Zheng-Li01 commented on Jun 1, 2026

    @Zheng-Li01
    Member

    This issue seems that same as this issue #14308, which have been fixed in 10.0.6-10.0.202 build, could you please have a try to install the latest. NET 10.0 to see if this issue fixed?

  13. rampaa commented on Jun 1, 2026

    @rampaa
    Author

    I don't think It's the same issue as #14308. That issue was about users experiencing crashes, this one is about getting bad data from the Clipboard after updating to .NET 10.

    Also @Shyam-Gupta said that the changes made in #14257 (which are not even fully back-ported to .NET 10 in #14296 AFAICT) does not address this issue according to their internal testings, see: #14257 (comment).

  14. Shyam-Gupta commented on Jun 2, 2026

    @Shyam-Gupta
    Member

    @rampaa We have identified the root cause of this bug. I will create a PR soon. Thanks.

  15. 19 remaining items

  16. rampaa commented on Sep 2, 2026

    @rampaa
    Author

    An opt-in AppContext switch would work well for me. Thank you, @Shyam-Gupta!

    it still returns an empty string if the QueryGet* API fails

    If this means that Clipboard.GetText() can still return an empty string when there is non-empty text in the Clipboard, I think it would be better for the Windows.Clipboard.ThrowExceptionsForGetAPIs switch to make these failures throw an exception as well. Otherwise, we still cannot reliably distinguish between the clipboard actually containing an empty string and a failure to retrieve the text.

  17. Shyam-Gupta commented on Sep 2, 2026

    @Shyam-Gupta
    Member

    This is the existing .NET 9 behavior with Clipboard.GetText() API as it internally calls QueryGetText() API which does not throw. The current changes won't change this behavior. In my rigorous stress testing, I found that with the new AppContext switch turned on, the GetText() will return empty string during < 0.5% of the instances and it is inline with the existing .NET 9 behavior.

  18. rampaa commented on Sep 2, 2026

    @rampaa
    Author

    Yes, I did read it's the existing behavior in .NET 9-. I was just saying that, especially after introducing a switch like Windows.Clipboard.ThrowExceptionsForGetAPIs, not returning an empty string for an error case and properly throwing would make Clipboard.GetText() much more consistent and reliable for people who opt into using the new switch. Not conflating a valid state with error state would be better IMHO, especially more so when there's a new switch for it where we specifically opt into getting exceptions for error states instead of getting empty strings.

  19. Shyam-Gupta commented on Sep 2, 2026

    @Shyam-Gupta
    Member

    The unintended change in API behavior introduced in .NET 10 would be addressed by the new switch. However, we cannot change the existing API behavior.

  20. Amy-Li03 commented on Sep 10, 2026

    @Amy-Li03
    Contributor

    Tested in the latest .NET 11 RC2 build: 11.0.100-rc.2.26458.109 + built private dls from the main branch of WinForms repo, it was fixed.
    When Windows.Clipboard.ThrowExceptionsForGetAPIs is set to true, Clipboard Get* APIs throw exceptions when clipboard access failures occur.
    When Windows.Clipboard.ThrowExceptionsForGetAPIs is set to false, Clipboard Get* APIs suppress clipboard-related exceptions and return an empty string.

  21. Olina-Zhang commented on Sep 24, 2026

    @Olina-Zhang
    Member

    Verified with .NET 11 Oct 2026 Update Validation test pass build: .NET 11.0.0-RC.2.26473.101, issue has been fixed with above test result.

  22. locked and limited conversation to collaborators on Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-Clipboard

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions