c# - Clipboard.Clear() 使 Outlook 和 Visual Studio 崩溃

标签 c# crash outlook clipboard memory-corruption

我遇到了我见过的最奇怪的错误之一。

看看这个从头开始创建的 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();
    }
}

没什么特别的,只是在单击按钮时清除剪贴板。

现在,如果我在 Visual Studio 的调试中运行它,清除剪贴板几次,然后关闭应用程序,然后尝试关闭 Visual Studio,Visual Studio 会崩溃并出现“内存损坏”异常。 这种情况不会 100% 发生,但一旦发生,我什至无法再启动 Visual Studio,我必须重新启动。

这似乎也会影响 Outlook。如果我打开了 Outlook,然后启动这个应用程序,清除剪贴板几次,然后切换回 Outlook,然后 Outlook 也会崩溃,就像 Visual Studio 一样,我必须重新启动才能再次使用它。

因此我开始非常怀疑 Windows 窗体剪贴板类在 Clear() 方法中的作用。为了证实我的理论,我使用了 WPF 附带的 Clipboard 类。 我在我的 WinForms 应用程序中引用了 PresentationCore.dll,并替换了:

System.Windows.Forms.Clipboard.Clear();

System.Windows.Clipboard.Clear();

现在 Visual Studio 和 Outlook 都不会崩溃。

我用谷歌搜索了一下,发现 this post没有明确的解决方案。

所以我想我的问题是,这是 WinForms Clipboard 类中的真正错误,还是我遗漏了什么?


附加信息:

  • Visual Studio 2012
  • 项目在 .NET 4.0 下运行。
  • 展望 2010

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 

最佳答案

这是一个 known bug这会导致 64 位机器上的内存损坏。 它已在 Windows 8 中修复。

解决方法是做

Clipboard.SetText("");

关于c# - Clipboard.Clear() 使 Outlook 和 Visual Studio 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19122971/

相关文章:

c# - 如何使用 ASP.NET 访问 Outlook 邮件?

visual-studio-2010 - 如何实现两个按钮点击事件

c# - Asp .Net 核心更新页面服务器端无需刷新

c# - 在 C# 中转换时区之间的时间

iphone - iPhone 上的访问崩溃日志数据

MySQL ...开始崩溃恢复

Blueprism 中的 Outlook 自动化

c# - 使用 Masterpage 时无法在内容页面中运行 javascript

c# - 如何在 C# 中比较两个哈希表的值

php - 为什么这个php正则表达式程序崩溃