I have one of the strangest mistakes I've ever seen.
Take a look at this Windows Forms application built from scratch:
static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { System.Windows.Forms.Clipboard.Clear(); } }
Nothing out of the ordinary, just clearing the clipboard at the touch of a button.
Now, if I run this in Debug from Visual Studio, clear the clipboard several times, then close the application, then try to close Visual Studio, crashing in Visual Studio with the exception “Memory corruption”. This does not happen in 100% of cases, but when this happens, I can no longer start Visual Studio, I need to reboot.
This also affects Outlook. If I have Outlook open, run this application, clean the clipboard several times, then switch back to Outlook, then Outlook will also fail, and like Visual Studio, I need to reboot to use it again.
So, I'm starting to be very suspicious of the Windows Forms Clipboard class in the Clear() method. To confirm my theory, I used the Clipboard class that comes with WPF. I referenced PresentationCore.dll in my WinForms application and replaced:
System.Windows.Forms.Clipboard.Clear();
with
System.Windows.Clipboard.Clear();
And none of them will work with either Visual Studio or Outlook.
I searched a bit for this information and found this post without a clear solution to the problem.
So, I think my question is, is this a real mistake in the WinForms Clipboard class, or am I missing something?
Additional Information:
- Visual studio 2012
- The project works under .NET 4.0.
- Outlook 2010
Column on collision with Outlook:
Unhandled exception at 0x77a7e3be in OUTLOOK.EXE: 0xC0000005: Access violation reading location 0x5c83d763. ntdll.dll!@RtlpLowFragHeapFree @8() + 0x2c bytes ntdll.dll!_RtlFreeHeap@12 () + 0x7e bytes kernel32.dll!_HeapFree@12 () + 0x14 bytes mshtml.dll!ParseExpandProperty() + 0x2d6 bytes mshtml.dll!PROPERTYDESC::HandleStyleComponentProperty() - 0xc2707 bytes mshtml.dll!MSCSSParser::SetStyleProperty() + 0x268 bytes mshtml.dll!MSCSSParser::Declaration() + 0x95 bytes mshtml.dll!MSCSSParser::Write() + 0x8b0 bytes mshtml.dll!BaseCSSParser::LoadFromStream() + 0x15a bytes mshtml.dll!CStyleSheet::DoParsing() + 0x18b bytes mshtml.dll!CStyleElementHelper::OnDwnChan() + 0x315 bytes mshtml.dll!CStyleElementHelper::SetCssCtx() - 0x130a5f bytes mshtml.dll!CStyleElementHelper::EnsureStyleDownload() + 0xfd bytes mshtml.dll!CStyleElementHelper::AttachExternalStyleSheet() + 0x97 bytes mshtml.dll!CLinkElement::HandleLinkedObjects() + 0xf0 bytes mshtml.dll!CLinkElement::Notify() - 0x189c54 bytes mshtml.dll!CHtmRootParseCtx::FlushNotifications() + 0x134 bytes mshtml.dll!CHtmRootParseCtx::Commit() + 0xb bytes mshtml.dll!CHtmParse::Commit() + 0x3c bytes mshtml.dll!CHtmPost::Broadcast() + 0xf bytes mshtml.dll!CHtmPost::Exec() + 0x11c bytes mshtml.dll!CHtmPost::Run() + 0x40 bytes mshtml.dll!PostManExecute() + 0x8e bytes mshtml.dll!PostManResume() + 0x96 bytes mshtml.dll!CHtmPost::OnDwnChanCallback() + 0x10 bytes mshtml.dll!CDwnChan::OnMethodCall() + 0x1f bytes mshtml.dll!GlobalWndOnMethodCall() + 0xf8 bytes mshtml.dll!GlobalWndProc() + 0x4517a bytes