This project has moved. For the latest updates, please go here.

How do you create a copy/clone of existing NetOffice object?

Nov 3, 2014 at 7:39 AM
Edited Nov 3, 2014 at 7:39 AM
How do you create a copy (or clone) of a NetOffice object so when you dispose the source object, the copied/cloned object is not disposed?

For example:

public void Method1(NetOffice.WordApi.Document document)
    NetOffice.WordApi.Document cloneDocument = document; /* How do you create copy here? */

public void Method2(NetOffice.WordApi.Document document)
    /* Code here to work with cloned document object even though source object was disposed */
Thank you!
Nov 3, 2014 at 8:48 AM
Edited Nov 3, 2014 at 8:51 AM
you can't clone the real instance. the real instance is not allive in your application.
you have to deal with the local proxies. (the real instance is alive in COM-Server(Word) memory.)

NO doesnt support the ICloneable interface currenlty. (if you need this, please create an issue ticket)
the easiest way is to create 2 proxies for the same instance in memory is as follows:

just like:

var doc1 = app.Documents[1]:
var doc2 = app.Documents[1]:

// doc2 proxie is still alive for the document instance and the document instance(in Word memory) is still allive until the valid proxy count is > 0.