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

There are several problems using COM from
.NET:

  • You cannot implement the Dispose pattern
    by utilizing the “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
    references.
  • COM reference is not released when a call to
    Marshal.ReleaseComObject is skipped due to an
    Exception.
  • 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
    2000.
  • The only solution to version independent COM is to use Late
    Bound operations but you miss all the features of a strongly typed
    language.

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 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.
http://www.codeproject.com/csharp/safecomwrapper.asp