Runtime callable wrapper (RCW) scope - process or application doma

S

Sunny

According to the docs for RCW (framework ver. 2.0 and up): "The runtime
creates exactly one RCW for each COM object, regardless of the number of
references that exist on that object. The runtime maintains a single RCW per
process for each object."

It's different for ver. 1.1 - the sentence about "one per process" is missing.

As there may be multiple AppDomains per process, and actually this is what
happens when you have multiple Outlook addins, installed with Shim Wizard,
what is the expected behavior of Marshal.ReleaseComObject(object)?

As an example:
If in my AppDomain (my addin) I have reference to a Message object in
Outlook, and (as per all good practices I read about), I use a loop around
Marshal.ReleaseComObject(message), is it going to release really all
references in the process, thus breaking another addin, which may hold a
reference to the same message?

Is there a difference in the implementation of this functionality between
..Net 1.1 and 2.0, or it is only a documentation change?

Thanks

P.S. I'm cross-posting, as I do not know which is the best group for this
question.
 
K

Ken Slovak - [MVP - Outlook]

I can't claim to be an RCW expert, but in my tests and experiences with
managed code, if you have 2 Outlook addins that are running in separate
AppDomains then calling Marshal.ReleaseComObject() on say the Inspectors
collection doesn't have any effect on the Inspectors collection object
instantiated in a different AppDomain. The Inspectors events will continue
to fire, and no RCW errors appear.

Of course things might be different if both addins were running in the same
AppDomain, but that's something you shouldn't be doing anyway.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top