Every time i close ArcMap (10.3.1) i get the following dialog: "OnShutdown: COM object that has been separated from its underlying RCW cannot be used." Why?

1061
1
11-08-2016 05:39 AM
ChaseHowse
New Contributor

No matter what .mxd i might be using, I get this message. The program appears to be working fine, except for this odd sounding message. Searching in Google brings up pages of "Stack Overflow" coding-type language that is Greek to me (so to speak). Any thoughts?

0 Kudos
1 Reply
BrentHoskisson
Occasional Contributor III

It is nearly impossible to diagnose this without looking at your code.  Usually you get this if the COM objects (i.e. arcobjects) do not shutdown in the proper order.  And with how .NET does garbage collection you cannot  guarantee the order  that the COM object will be shut down.

A way to circumvent this is to place the following code when you don't need an object any more:

System.Runtime.InteropServices.Marshal.ReleaseComObject(<object>);

I usually put this in a finally block wherever I create and use Cursor objects.  Just setting them to null is not enough.

Note that there are other objects that use cursors in a hidden manor, like IFeatureClass and any IEnum... classes that could benefit from the ReleaseComObject function.  

ESRI has also created a function:

ESRI.ArcGIS.ADF.COMSupport.AOUninitialize.Shutdown();

which you can put as one of the last statements in your close scripts and it does reasonably well - but not perfect - at preventing this error.

I hope this helps.

Good Luck,

Brent Hoskisson