如何避免System.Runtime.InteropServices.COMException? [英] How to avoid a System.Runtime.InteropServices.COMException?

查看:2594
本文介绍了如何避免System.Runtime.InteropServices.COMException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的微软Surface的项目,我总是得到很多的下列情况除外:

 MuReSe.vshost.exe(管理(V2.0.50727)):加载C:\ WINDOWS \组装\ GAC_32 \ mscorlib程序\ 2.0.0.0__b77a5c561934e089 \ mscorlib.dll中'
MuReSe.vshost.exe(管理(V2.0.50727)):加载'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'
MuReSe.vshost.exe(管理(V2.0.50727)):加载'C:\Windows\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'
MuReSe.vshost.exe(管理(V2.0.50727)):加载C:\ WINDOWS \组装\ GAC_MSIL \ SYSTEM \ 2.0.0.0__b77a5c561934e089 \ System.dll中'
MuReSe.vshost.exe(管理(V2.0.50727)):加载C:\ WINDOWS \组装\ GAC_MSIL \ System.Drawing中\ 2.0.0.0__b03f5f7f11d50a3a \ System.Drawing.dll程序
MuReSe.vshost.exe(管理(V2.0.50727)):加载'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'
MuReSe.vshost.exe(管理(V2.0.50727)):加载'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'
MuReSe.vshost.exe(管理(V2.0.50727)):加载C:\用户\ Roflcoptr \文档\ Visual Studio 2008的\项目\ MuReSe \ MuReSe \斌\调试\ MuReSe.vshost.exe
MuReSe.vshost.exe(管理(V2.0.50727)):加载C:\ WINDOWS \组装\ GAC_MSIL \ System.Core程序\ 3.5.0.0__b77a5c561934e089 \ System.Core.dll的'
MuReSe.vshost.exe(管理(V2.0.50727)):加载C:\ WINDOWS \组装\ GAC_MSIL \ System.Xml.Linq的\ 3.5.0.0__b77a5c561934e089 \ System.Xml.Linq.dll
MuReSe.vshost.exe(管理(V2.0.50727)):加载'C:\Windows\assembly\GAC_MSIL\System.Data.DataSetExtensions\3.5.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'
MuReSe.vshost.exe(管理(V2.0.50727)):加载C:\ WINDOWS \组装\ GAC_32 \ System.Data这\ 2.0.0.0__b77a5c561934e089 \ System.Data.dll中'
MuReSe.vshost.exe(管理(V2.0.50727)):加载C:\ WINDOWS \组装\ GAC_MSIL \的System.Xml \ 2.0.0.0__b77a5c561934e089 \ system.xml.dll的'
MuReSe.vshost.exe(管理(V2.0.50727)):加载C:\ WINDOWS \组装\ GAC_MSIL \ WindowsBase \ 3.0.0.0__31bf3856ad364e35 \ WindowsBase.dll中'
MuReSe.vshost.exe(管理(V2.0.50727)):加载C:\ WINDOWS \组装\ GAC_32 \ presentationCore \ 3.0.0.0__31bf3856ad364e35 \ presentationCore.dll
MuReSe.vshost.exe(管理(V2.0.50727)):加载'C:\Windows\assembly\GAC_MSIL\$p$psentationFramework\3.0.0.0__31bf3856ad364e35\$p$psentationFramework.dll'
MuReSe.vshost.exe(管理(V2.0.50727)):加载C:\ WINDOWS \组装\ GAC_MSIL \ Microsoft.Surface \ 1.0.0.0__31bf3856ad364e35 \ Microsoft.Surface.dll
MuReSe.vshost.exe(管理(V2.0.50727)):加载'C:\Windows\assembly\GAC_MSIL\Microsoft.Surface.$p$psentation\1.0.0.0__31bf3856ad364e35\Microsoft.Surface.$p$psentation.dll'
MuReSe.vshost.exe(管理(V2.0.50727)):加载'C:\Windows\assembly\GAC_MSIL\Microsoft.Surface.$p$psentation.Generic\1.0.0.0__31bf3856ad364e35\Microsoft.Surface.$p$psentation.Generic.dll'
线程vshost.NotifyLoad(0x1504)已退出与code 0(为0x0)。
线程vshost.LoadReference(0x131c)已退出与code 0(为0x0)。
MuReSe.vshost.exe(管理(V2.0.50727)):加载C:\用户\ Roflcoptr \文档\ Visual Studio 2008的\项目\ MuReSe \ MuReSe \斌\调试\ MuReSe.exe',符号加载。
MuReSe.vshost.exe(管理(V2.0.50727)):加载'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'
步骤为:步进超过方法不带符号MuReSe.App.App
MuReSe.vshost.exe(管理(V2.0.50727)):加载'C:\Windows\assembly\GAC_MSIL\Microsoft.Surface.Shell.ShellApi\1.0.0.0__31bf3856ad364e35\Microsoft.Surface.Shell.ShellApi.dll'
MuReSe.vshost.exe(管理(V2.0.50727)):加载'C:\Windows\assembly\GAC_MSIL\Microsoft.Surface.Common\1.0.0.0__31bf3856ad364e35\Microsoft.Surface.Common.dll'
第一个机会异常类型'System.Runtime.InteropServices.COMException'在Microsoft.Surface.Shell.ShellApi.dll发生
第一个机会异常类型的Microsoft.Surface.Common.ProcessCommunicationException在Microsoft.Surface.Shell.ShellApi.dll发生
第一次机会异常的类型'System.Threading.WaitHandleCannotBeOpenedException在mscorlib.dll中发生
MuReSe.vshost.exe(管理(V2.0.50727)):加载'C:\Windows\assembly\GAC_MSIL\Microsoft.Surface.Core\1.0.0.0__31bf3856ad364e35\Microsoft.Surface.Core.dll'
第一个机会异常类型'System.Runtime.InteropServices.COMException'在Microsoft.Surface.Core.dll发生
第一次机会异常的类型'System.IO.FileNotFoundException'的mscorlib.dll中发生
第一个机会异常类型'System.Runtime.InteropServices.COMException'在Microsoft.Surface.Core.dll发生
第一个机会异常类型'System.Runtime.InteropServices.COMException'在Microsoft.Surface.Core.dll发生
第一个机会异常类型'System.Runtime.InteropServices.COMException'在Microsoft.Surface.Core.dll发生
第一个机会异常类型'System.Runtime.InteropServices.COMException'在Microsoft.Surface.Core.dll发生
第一个机会异常类型'System.Runtime.InteropServices.COMException'在Microsoft.Surface.Core.dll发生
第一个机会异常类型'System.Runtime.InteropServices.COMException'在Microsoft.Surface.Core.dll发生
第一个机会异常类型'System.Runtime.InteropServices.COMException'在Microsoft.Surface.Core.dll发生
第一个机会异常类型'System.Runtime.InteropServices.COMException'在Microsoft.Surface.Core.dll发生
第一个机会异常类型'System.Runtime.InteropServices.COMException'在Microsoft.Surface.Core.dll发生
第一个机会异常类型'System.Runtime.InteropServices.COMException'在Microsoft.Surface.Core.dll发生
第一个机会异常类型'System.Runtime.InteropServices.COMException'在Microsoft.Surface.Core.dll发生
第一个机会异常类型'System.Runtime.InteropServices.COMException'在Microsoft.Surface.Core.dll发生
第一个机会异常类型'System.Runtime.InteropServices.COMException'在Microsoft.Surface.Core.dll发生
第一个机会异常类型'System.Runtime.InteropServices.COMException'在Microsoft.Surface.Core.dll发生
第一个机会异常类型'System.Runtime.InteropServices.COMException'在Microsoft.Surface.Core.dll发生
第一个机会异常类型'System.Runtime.InteropServices.COMException'在Microsoft.Surface.Core.dll发生
 

最后一个异常被抛出所有的时间,直到我停止该程序。我已经评论了我所有的code,A我拼命地跑有什么比已建成的code中的应用,但同样的情况。

我如何纠正?我才发现这个参考:

<一个href="http://www.mobydisk.com/softdev/techinfo/dotnetexceptions.html">http://www.mobydisk.com/softdev/techinfo/dotnetexceptions.html

有这样说的:

  

这是引发的异常时   无法识别的HRESULT从返回   COM方法调用。

但我不知道这意味着什么......

====编辑====

我也跟着下面调试异常答案的建议。这是详细报道:

 发生System.Runtime.InteropServices.COMException
  消息=没有注册类(从HRESULT异常:0x80040154的(REGDB_E_CLASSNOTREG))
  来源= Microsoft.Surface.Shell.ShellApi
  错误code = -2147221164
  堆栈跟踪:
       在Microsoft.Surface.Shell.NativeMethods.CoCreateInstance(GUID rclsid,对象pUnkOuter,CLSCTX dwClsContext中GUID RIID)
  的InnerException:
 

而debuger停在构造函数调用:

 公共主窗口()
        {
            的InitializeComponent();

            //添加处理程序应用激活事件
            AddActivati​​onHandlers();

           // AssemblyParser分析器=新AssemblyParser();
            //parser.parse();

           // DirSearch(@C:\用户\ Roflcoptr \文档\ Visual Studio 2008的\项目\ TestClass.dll \);
        }
 

我在构造函数开始停止正确的:

 公共主窗口()
 

解决方案

您code(或code调用你)正在调用COM方法是返回一个未知的值。如果你能找到那么你就成功了一半。

您可以尝试当异常被抛出打破。转到调试>例外... ,然后使用查找... 选项找到 System.Runtime.InteropServices.COMException 。勾选该选项,打破当它抛出,然后调试应用程序。

希望这将打破地方有意义的,你就可以追溯,找到错误的根源。

In my Microsoft Surface project, I always get a lot of the following exceptions:

'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Users\Roflcoptr\Documents\Visual Studio 2008\Projects\MuReSe\MuReSe\bin\Debug\MuReSe.vshost.exe'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Xml.Linq\3.5.0.0__b77a5c561934e089\System.Xml.Linq.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Data.DataSetExtensions\3.5.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\WindowsBase\3.0.0.0__31bf3856ad364e35\WindowsBase.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_32\PresentationCore\3.0.0.0__31bf3856ad364e35\PresentationCore.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\PresentationFramework\3.0.0.0__31bf3856ad364e35\PresentationFramework.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.Surface\1.0.0.0__31bf3856ad364e35\Microsoft.Surface.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.Surface.Presentation\1.0.0.0__31bf3856ad364e35\Microsoft.Surface.Presentation.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.Surface.Presentation.Generic\1.0.0.0__31bf3856ad364e35\Microsoft.Surface.Presentation.Generic.dll'
The thread 'vshost.NotifyLoad' (0x1504) has exited with code 0 (0x0).
The thread 'vshost.LoadReference' (0x131c) has exited with code 0 (0x0).
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Users\Roflcoptr\Documents\Visual Studio 2008\Projects\MuReSe\MuReSe\bin\Debug\MuReSe.exe', Symbols loaded.
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'
Step into: Stepping over method without symbols 'MuReSe.App.App'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.Surface.Shell.ShellApi\1.0.0.0__31bf3856ad364e35\Microsoft.Surface.Shell.ShellApi.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.Surface.Common\1.0.0.0__31bf3856ad364e35\Microsoft.Surface.Common.dll'
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.Surface.Shell.ShellApi.dll
A first chance exception of type 'Microsoft.Surface.Common.ProcessCommunicationException' occurred in Microsoft.Surface.Shell.ShellApi.dll
A first chance exception of type 'System.Threading.WaitHandleCannotBeOpenedException' occurred in mscorlib.dll
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.Surface.Core\1.0.0.0__31bf3856ad364e35\Microsoft.Surface.Core.dll'
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.Surface.Core.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.Surface.Core.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.Surface.Core.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.Surface.Core.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.Surface.Core.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.Surface.Core.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.Surface.Core.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.Surface.Core.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.Surface.Core.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.Surface.Core.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.Surface.Core.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.Surface.Core.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.Surface.Core.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.Surface.Core.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.Surface.Core.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.Surface.Core.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.Surface.Core.dll

The last Exception is thrown all the time until i stop the program. I already commented out all of my code, a I runned the application with nothing than the already built in code, but the same happens.

How can I correct that? I only found this reference:

http://www.mobydisk.com/softdev/techinfo/dotnetexceptions.html

There it says:

The exception that is thrown when an unrecognized HRESULT is returned from a COM method call.

But I don't know what this means....

====EDIT====

I followed the suggestion in the answer below to debug the exception. This is the detailed report:

System.Runtime.InteropServices.COMException occurred
  Message=Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  Source=Microsoft.Surface.Shell.ShellApi
  ErrorCode=-2147221164
  StackTrace:
       at Microsoft.Surface.Shell.NativeMethods.CoCreateInstance(Guid rclsid, Object pUnkOuter, CLSCTX dwClsContext, Guid riid)
  InnerException: 

And the debuger stopped at the constructor call:

 public MainWindow()
        {
            InitializeComponent();

            // Add handlers for Application activation events
            AddActivationHandlers();

           // AssemblyParser parser = new AssemblyParser();
            //parser.parse();

           // DirSearch(@"C:\Users\Roflcoptr\Documents\Visual Studio 2008\Projects\TestClass.dll\");
        }

I stopped right at the start of the constructor:

public MainWindow()

解决方案

Your code (or some code called by you) is making a call to a COM method which is returning an unknown value. If you can find that then you're half way there.

You could try breaking when the exception is thrown. Go to Debug > Exceptions... and use the Find... option to locate System.Runtime.InteropServices.COMException. Tick the option to break when it's thrown and then debug your application.

Hopefully it will break somewhere meaningful and you'll be able to trace back and find the source of the error.

这篇关于如何避免System.Runtime.InteropServices.COMException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆