dotnet / dotnet/winforms

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

Closed
#14,322 28 comments 2 reactions 1 assignee Assigned to @Shyam-Gupta View on GitHub
area-Clipboard
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
20h 23m
Merged PRs (30d)
103

Description

### 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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.