Tag Archive for COM

Safe COM: Managed Disposable Strongly Typed safe wrapper to late bound COM

There are several problems using COM from

  • You cannot implement the Dispose pattern
    by utilizing the “ "cs-keyword">using” block in order to safely dispose
    COM references.
  • You cannot guaranty COM references are finalized. There’s no
    way to implement “~Destructor()” for COM
  • COM reference is not released when a call to
    Marshal.ReleaseComObject is skipped due to an
  • When you “Add Reference…” to a COM library, the reference is
    version specific. So, if you add a reference to the Office 2003 COM
    library, it does not work properly when deployed to Office
  • The only solution to version independent COM is to use Late
    Bound operations but you miss all the features of a strongly typed

Let’s solve all these problems. We want to use a Managed
strongly typed
approach to Late Bound COM operations and
also utilize the Dispose pattern on COM objects. The
solution proposed "http://www.codeproject.com/csharp/safecomwrapper.asp">here
works for any COM object which can be Microsoft Office COM
libraries, IE & DHTML objects and even your own COM objects.
You should use this approach whenever you are dealing with any type
of COM library.

If you like this solution, please vote for me.