[英]Clipboard.Clear() crashes Outlook & Visual Studio
I have one of the weirdest bugs I have ever seen. 我有一个我见过的最奇怪的错误。
Take a look at this Windows Forms application created from scratch: 看一下从头开始创建的Windows窗体应用程序:
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 fancy, just clearing the clipboard when the button is clicked. 没有什么好看的,只需在单击按钮时清除剪贴板。
Now, if I run this in Debug from Visual Studio, clear the clipboard a few times, then close the app, then attempt to close Visual Studio, Visual Studio crashes with a "Memory corruption" exception. 现在,如果我在Visual Studio的Debug中运行它,清除剪贴板几次,然后关闭应用程序,然后尝试关闭Visual Studio,Visual Studio崩溃并出现“内存损坏”异常。 This is not happening 100% of the time, but when it does, I cannot even start Visual Studio anymore, I have to reboot.
这种情况在100%的情况下都没有发生,但是当它发生时,我甚至无法启动Visual Studio,我必须重新启动。
This seems to also affect Outlook. 这似乎也影响Outlook。 If I have Outlook opened, then start this app, clear the clipboard a few times, then switch back to Outlook, then Outlook also crashes, and just like Visual Studio, I have to reboot to be able to use it again.
如果我打开Outlook,然后启动此应用程序,清除剪贴板几次,然后切换回Outlook,然后Outlook也崩溃,就像Visual Studio一样,我必须重新启动才能再次使用它。
So I am starting to be very suspicious of what the Windows Forms Clipboard class does in the Clear()
method. 所以我开始非常怀疑Windows Forms Clipboard类在
Clear()
方法中的作用。 To confirm my theory, I used the Clipboard class which comes with WPF. 为了证实我的理论,我使用了WPF附带的Clipboard类。 I referenced PresentationCore.dll in my WinForms application, and replaced:
我在WinForms应用程序中引用了PresentationCore.dll,并替换为:
System.Windows.Forms.Clipboard.Clear();
with 同
System.Windows.Clipboard.Clear();
And now neither Visual Studio nor Outlook crashes. 现在,Visual Studio和Outlook都没有崩溃。
I googled this a bit, and found this post with no clear solution to the problem. 我用Google搜索了一下,发现这篇文章没有明确解决问题的方法。
So I guess my question is, is this a real bug in the WinForms Clipboard class, or am I missing something? 所以我想我的问题是,这是WinForms剪贴板课程中的一个真正的错误,还是我错过了什么?
Additional info: 附加信息:
Outlook crash callstack : Outlook崩溃callstack:
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
in .Net 4.0 the code is not enough. 在.Net 4.0中,代码还不够。 an exception occurred.
发生了异常。
Clipboard.SetText("");
use this code.. 使用此代码..
Clipboard.SetDataObject("", false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.