This project has moved and is read-only. For the latest updates, please go here.
/* taken from Tutorial01.csproj
All objects in NetOffice which are based on CoClasses or Interfaces are wrapping COM Proxies. It's necessary to release a created COM Proxy by the client caller.
This tells the COM Server (meaning your office application) that you do not need the instance any longer.

In the MS Interop Assemblies you do that with Marshal.ReleaseComObject(object proxy);
In NetOffice any object has the Method Dispose() to do that.
An implemented Proxy Table in NetOffice makes it possible that you do not have to call Dispose() for any (implicitly) created object.
This tutorial shows you how to use the Dispose() method to release an object and its created child objects.

See chapter1 and chapter5 in technical documentation for further info.


public void Tutorial01Main()

   /* NetOffice manages COM Proxies for you to avoid any kind of memory leaks           
   *  and make sure your application instance removes from process list if you want. */	 
   // Initialize Api COMObject Support 

   // start application
   Excel.Application application = new Excel.Application();
   application.DisplayAlerts = false;

   Excel.Workbook book = application.Workbooks.Add();
    * now we have 2 new COM Proxies created.
    * the first proxy was created while accessing the Workbooks collection from 
* application the second proxy was created by the Add() method from Workbooks
* and stored now in book with the application object we have 3 created proxies
* now. the workbooks proxy was created about application and the book proxy was
* created about the workbooks. * NetOffice holds the proxies now in a list as follows: * * Application * + Workbooks * + Workbook * * any object in NetOffice implements the IDisposible Interface. * use the Dispose() Method to release an object. the method release all created
* child proxies too. */
application.Quit(); application.Dispose(); /* * the application object is ouer root object * dispose them release himself and any childs of application, in this case workbooks
* and workbook the excel instance are now removed from process list */
MessageBox.Show(this, "Done!", this.Text, MessageBoxButtons.OK,
MessageBoxIcon.Information); }

Last edited Jan 5, 2012 at 10:34 AM by SebastianDotNet, version 28


robvon Aug 19, 2013 at 8:41 PM 
Jan, I agree. The 'using' statement would indeed make it obvious to the reader of the code where the RCW's are being created and released and NetOffice examples should show this. However in the case of implicit wrapper creation, this could make the code more wordy and puts the onus back onto the developer. I think that NetOffice offers the best of both worlds - 'using' where it fits nicely and occasionally a Dispose() to pick up on any instances you may miss or choose to keep for a while and pass around.

janoman Jun 24, 2011 at 9:46 PM 
Hi, I think it would be better to use the using statement instead of explicit use of the Dispose Method.
I love this project because it make it easy to use MS Offide within .NET applications. Thank You for this great job and provide more and more functionality.