Repository navigation
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
Activity
rampaa commentedon Jan 29, 2026
Possibly caused by dotnet/wpf#10544
lindexi commentedon Jan 30, 2026
Yes, I agree with you.
lindexi commentedon Jan 30, 2026
@rampaa Could you try the code in WinForms?
I expected the same behavior as WPF, and then we can bring this issues to WinForms repo.
You can find my code in: https://github.com/lindexi/lindexi_gd/tree/4174cf49c4dd46acfa7d06080675d9499b4bdb85/Workbench/KunalljayfewereNefefoke
rampaa commentedon Jan 30, 2026
@lindexi
The regression (and the dump file itself) was reported to me by a long-time user of one of my apps. Unfortunately, I can’t trigger the exception in WPF or WinForms at will.
Fortunately, we do have a full dump file. The exception appears to occur in the
TryGetHGLOBALDatamethod inside theSystem.Private.Windows.Ole.Compositionclass, which I believe started being used in WPF after dotnet/wpf#10544. Given this, it seems reasonable to assume that it would also affect WinForms.Tagging @JeremyKuhne, since he is the owner of that PR and would likely have the most context on this change (and probably on #14322 as well).
JeremyKuhne commentedon Jan 30, 2026
@rampaa We don't have access to the site where you have the dump. Can you include the call stack(s)?
rampaa commentedon Jan 30, 2026
@JeremyKuhne Sure, here it is:
The crash happens at the
PInvokeCore.ReleaseStgMedium(ref medium);line.Do you have any site that you are able to access where I can upload the full dump file in case you need it for further details?
JeremyKuhne commentedon Jan 30, 2026
@rampaa The only thing I'm aware of is attaching to a VS Feedback ticket, which is where we point people when they don't want the general public to see things. I'm taking a look now, I'll let you know.
JeremyKuhne commentedon Jan 30, 2026
It appears we're double releasing here. Erp. We're freeing the
STGMEDIUMafter releasing theHGLOBAL.Fyi: I'm no longer on the WinForms team, but I'm actively working with them to get the fix made.
rampaa commentedon Jan 30, 2026
Thank you very much for the quick reply. I’m glad to hear this is being actively worked on.
Is there anyone familiar with the WinForms side of the clipboard code who could shed some light on the other clipboard regression that my users are experiencing after migrating to .NET 10? Although the issue was discovered in a WPF app, which is why I opened it in this repo, the clipboard code is now shared. This makes me think the problem may affect both WPF and WinForms. It would be great if someone with relevant context could take a look and help clarify why the behavior changed, or perhaps offer a workaround.
JeremyKuhne commentedon Jan 30, 2026
@rampaa looking at that one too.
JeremyKuhne commentedon Jan 30, 2026
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.
Migrate back to .NET 9 until a fix for https://github.com/dotnet/wpf/…
Fixes bug https://github.com/dotnet/wpf/issues/11401
[release/10.0]: Avoid double free of STGMEDIUM while fetching stream …
Zheng-Li01 commentedon Mar 31, 2026
Verified the issue with .NET April 2026 update test pass build 10.0.6-10.0.202 build, using the attached app to test that have the same result with private testing, and no new issue found. closed the issue.
TestApp.zip
[release/10.0]: Avoid double free of STGMEDIUM while fetching stream …