Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
439 views
in Technique[技术] by (71.8m points)

c# - How to avoid a 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:WindowsassemblyGAC_32mscorlib2.0.0.0__b77a5c561934e089mscorlib.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:WindowsassemblyGAC_MSILMicrosoft.VisualStudio.HostingProcess.Utilities10.0.0.0__b03f5f7f11d50a3aMicrosoft.VisualStudio.HostingProcess.Utilities.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:WindowsassemblyGAC_MSILSystem.Windows.Forms2.0.0.0__b77a5c561934e089System.Windows.Forms.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:WindowsassemblyGAC_MSILSystem2.0.0.0__b77a5c561934e089System.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:WindowsassemblyGAC_MSILSystem.Drawing2.0.0.0__b03f5f7f11d50a3aSystem.Drawing.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:WindowsassemblyGAC_MSILMicrosoft.VisualStudio.HostingProcess.Utilities.Sync10.0.0.0__b03f5f7f11d50a3aMicrosoft.VisualStudio.HostingProcess.Utilities.Sync.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:WindowsassemblyGAC_MSILMicrosoft.VisualStudio.Debugger.Runtime10.0.0.0__b03f5f7f11d50a3aMicrosoft.VisualStudio.Debugger.Runtime.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:UsersRoflcoptrDocumentsVisual Studio 2008ProjectsMuReSeMuReSeinDebugMuReSe.vshost.exe'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:WindowsassemblyGAC_MSILSystem.Core3.5.0.0__b77a5c561934e089System.Core.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:WindowsassemblyGAC_MSILSystem.Xml.Linq3.5.0.0__b77a5c561934e089System.Xml.Linq.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:WindowsassemblyGAC_MSILSystem.Data.DataSetExtensions3.5.0.0__b77a5c561934e089System.Data.DataSetExtensions.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:WindowsassemblyGAC_32System.Data2.0.0.0__b77a5c561934e089System.Data.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:WindowsassemblyGAC_MSILSystem.Xml2.0.0.0__b77a5c561934e089System.Xml.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:WindowsassemblyGAC_MSILWindowsBase3.0.0.0__31bf3856ad364e35WindowsBase.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:WindowsassemblyGAC_32PresentationCore3.0.0.0__31bf3856ad364e35PresentationCore.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:WindowsassemblyGAC_MSILPresentationFramework3.0.0.0__31bf3856ad364e35PresentationFramework.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:WindowsassemblyGAC_MSILMicrosoft.Surface1.0.0.0__31bf3856ad364e35Microsoft.Surface.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:WindowsassemblyGAC_MSILMicrosoft.Surface.Presentation1.0.0.0__31bf3856ad364e35Microsoft.Surface.Presentation.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:WindowsassemblyGAC_MSILMicrosoft.Surface.Presentation.Generic1.0.0.0__31bf3856ad364e35Microsoft.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:UsersRoflcoptrDocumentsVisual Studio 2008ProjectsMuReSeMuReSeinDebugMuReSe.exe', Symbols loaded.
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:WindowsassemblyGAC_MSILSystem.Configuration2.0.0.0__b03f5f7f11d50a3aSystem.Configuration.dll'
Step into: Stepping over method without symbols 'MuReSe.App.App'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:WindowsassemblyGAC_MSILMicrosoft.Surface.Shell.ShellApi1.0.0.0__31bf3856ad364e35Microsoft.Surface.Shell.ShellApi.dll'
'MuReSe.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:WindowsassemblyGAC_MSILMicrosoft.Surface.Common1.0.0.0__31bf3856ad364e35Microsoft.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:WindowsassemblyGAC_MSILMicrosoft.Surface.Core1.0.0.0__31bf3856ad364e35Microsoft.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, and I ran the application with nothing other 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:UsersRoflcoptrDocumentsVisual Studio 2008ProjectsTestClass.dll");
        }

I stopped right at the start of the constructor:

public MainWindow()
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...