-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Description
After upgrading to .NET 10, an application intermittently crashes with an unhandled exception:
Indirect call guard check detected invalid control transfer
The crash occurs inside Clipboard.ContainsText() when it is called in response to WM_CLIPBOARDUPDATE. The same code path worked reliably in previous .NET versions.
Reproduction Steps
- Create a WPF application targeting .NET 10.
- Register for clipboard notifications using
AddClipboardFormatListener. - Handle
WM_CLIPBOARDUPDATEin a custom WndProc. - Call
Clipboard.ContainsText()asynchronously from the message handler.
Minimal repro code:
private static nint WndProc(nint hwnd, int msg, nint wParam, nint lParam, ref bool handled)
{
if (msg == WM_CLIPBOARDUPDATE)
{
_ = Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Send, () =>
{
_ = CopyFromClipboard();
});
handled = true;
}
return 0;
}private async Task<bool> CopyFromClipboard()
{
while (Clipboard.ContainsText())
{
try
{
string text = Clipboard.GetText();
return true;
}
catch (ExternalException)
{
await Task.Delay(5).ConfigureAwait(true);
}
}
return false;
}Run the app and frequently change clipboard contents (e.g., copy text rapidly from different applications).
Eventually, the process crashes with the CFG error.
Expected behavior
Clipboard.ContainsText() should either:
- Return a boolean result, or
- Throw a managed exception (e.g.,
ExternalException) if the clipboard is temporarily unavailable.
It should never cause a native crash or trigger a Control Flow Guard violation.
Actual behavior
The application crashes with an unhandled native exception:
Unhandled exception at 0x00007FFE23CC728F in JL.exe:
Indirect call guard check detected invalid control transfer.
A crash dump shows the fault occurring inside Clipboard.ContainsText().
The exception cannot be caught in managed code.
Here's the full dump: https://mega.nz/file/z0FwBTCB#sssXKDAROlucZkEEVLPR5LKwxTfNex30nPqbgUl99mM
Regression?
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