[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:\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, 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:\Users\Roflcoptr\Documents\Visual Studio 2008\Projects\TestClass.dll\");
        }

I stopped right at the start of the constructor:

public MainWindow()

This question is related to c# .net wpf exception pixelsense

The answer is


I got this exception while coping a object(variable) Matrix Array into Excel sheet. The solution to this is, Matrix array Index(i,j) must start from (0,0) whereas Excel sheet should start with Matrix Array index (i,j) from (1,1) .

I hope you this concept.


I came across System.Runtime.InteropServices.COMException while opening a project solution. Sometimes user doesn't have enough priveleges to run some COM Methods. I ran Visual Studio as Administrator and the exception was gone.


Probably you are trying to access the excel with the index 0, please note that Excel rows/columns start from 1.


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to .net

You must add a reference to assembly 'netstandard, Version=2.0.0.0 How to use Bootstrap 4 in ASP.NET Core No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization .net Core 2.0 - Package was restored using .NetFramework 4.6.1 instead of target framework .netCore 2.0. The package may not be fully compatible Update .NET web service to use TLS 1.2 EF Core add-migration Build Failed What is the difference between .NET Core and .NET Standard Class Library project types? Visual Studio 2017 - Could not load file or assembly 'System.Runtime, Version=4.1.0.0' or one of its dependencies Nuget connection attempt failed "Unable to load the service index for source" Token based authentication in Web API without any user interface

Examples related to wpf

Error: the entity type requires a primary key Reportviewer tool missing in visual studio 2017 RC Pass command parameter to method in ViewModel in WPF? Calling async method on button click Setting DataContext in XAML in WPF How to resolve this System.IO.FileNotFoundException System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll? Binding an Image in WPF MVVM How to bind DataTable to Datagrid Setting cursor at the end of any text of a textbox

Examples related to exception

Connection Java-MySql : Public Key Retrieval is not allowed How to print an exception in Python 3? ASP.NET Core Web API exception handling Catching FULL exception message How to get exception message in Python properly What does "Fatal error: Unexpectedly found nil while unwrapping an Optional value" mean? what does Error "Thread 1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)" mean? Argument Exception "Item with Same Key has already been added" The given key was not present in the dictionary. Which key? sql try/catch rollback/commit - preventing erroneous commit after rollback

Examples related to pixelsense

How to avoid a System.Runtime.InteropServices.COMException?