当前位置:  开发笔记 > 编程语言 > 正文

在桌面上拖动文件时可能导致COMExceptions的原因是什么?

如何解决《在桌面上拖动文件时可能导致COMExceptions的原因是什么?》经验,为你挑选了1个好方法。

它不会崩溃,我在这里提到的所有异常只能在Visual Studio的Output窗口中看到.这是Dragging:
WPF 的实现:


    
    

cs代码:

private void DragShortcut(object sender, MouseButtonEventArgs e)
{
    if (e.LeftButton != MouseButtonState.Pressed)
        return;

    var dataObject = new DataObject(DataFormats.FileDrop, new[] { Options.DragDropOptions.ShortcutPath });
    DragDrop.DoDragDrop(Shortcut, dataObject, DragDropEffects.Copy);
}

一切似乎按预期工作,但每次我在桌面或资源管理器窗口上拖动东西时,我在Visual Studio的"输出"窗口中收到以下消息:

...
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in PresentationCore.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in PresentationCore.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in PresentationCore.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in PresentationCore.dll
A first chance exception of type 'System.NotImplementedException' occurred in PresentationCore.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in PresentationCore.dll
... 

当Visual Studio设置为停止此类异常时,我可以看到以下异常:

System.Runtime.InteropServices.COMException was unhandled
Message: An exception of type 'System.Runtime.InteropServices.COMException' occurred in PresentationCore.dll and wasn't handled before a managed/native boundary
Additional information: Invalid FORMATETC-Structure (Exception HRESULT: 0x80040064 (DV_E_FORMATETC))

System.NotImplementedException was unhandled
Message: An exception of type 'System.NotImplementedException' occurred in PresentationCore.dll and wasn't handled before a managed/native boundary
Additional information: The method or operation is not implemented.

它不会导致崩溃或任何事情,作为开发人员,我在背景中发生这样的事情会让我感到不舒服.有没有人有一个想法它会是什么?

编辑:
这个问题看起来很像我的,但似乎有另一个原因和解决方案.



1> Hans Passant..:

这完全正常.无论您拖动的另一个进程的窗口是什么,都会使该进程查看您拖动的对象,以查看它是否支持特定格式,还是可以将对象转换为其他格式.在引擎盖下完成COM调用.如果答案为"是",那么您会看到光标发生变化,表明您可以放弃.

WPF中的IDataObject接口实现通过抛出异常来表示"否".在.NET程序中生成COM失败代码的常规方法.CLR将该异常转换为COM错误代码HRESULT,以告知进程它无法正常工作.注意Exeption类如何具有HResult属性,这是进程看到的属性.

如果您要求,调试器会尽职尽责地显示"第一次机会"异常通知.右键单击"输出"窗口,"异常消息"选项,默认情况下处于启用状态.没有什么事实出错,异常被捕获并优雅地处理.功能,而不是错误.

推荐阅读
k78283381
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有