|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
Troubleshooting Exceptions: System.Runtime.InteropServices.COMException
A COMException exception is thrown when an unrecognized HRESULT is returned from a COM method call.
The common language runtime (CLR) transforms well-known HRESULTS to .NET exceptions, enabling COM objects to return meaningful error information to managed clients. The HRESULT to exception mapping also works in the other direction by returning specific HRESULTS to unmanaged clients.
When passing late-bound parameters to methods of Microsoft Office objects, a COMException exception may be thrown when the objects are COM objects. The late binder assumes that such method calls involve a ByRef parameter and that the property you pass has a Set accessor. If the property does not, the .NET Framework generates a MissingMethodException exception (HRESULT CORE_E_MISSINGMETHOD). To work around this behavior, use early-bound objects or pass a variable instead of a property of the object.