Select to view content in your preferred language

Getting error "COM object that has been separated from its underlying RC

3105
3
10-11-2011 05:52 PM
MichaelRutkowski
Regular Contributor
I'm having a particularly odd issue occurring. I created a custom component using both the addin model and custom COM dll.

When I use the tool under one login (administrative privileges), I have no issues. The other login crashes at the oddest spot.
It crashes when I try to obtain a feature using the getfeature method from a featureclass. The error actually seems to occur as the result of obtaining the featureclass from the layer.
if not pLayer is nothing then
if not pLayer.FeatureClass is nothing then
  'error occurs here:
    pFeat = pLayer.FeatureClass.GetFeature(id)
end if
end if

When it crashes, I get the following error:

Error: CopyPasteTool **COM object that has been separated from its underlying RCW cannot be used.** at CopyPasteTool.bas_LoadDataTools.ListSelectedFeatures() select item in list (list items are not updated after first selection) ESRI.arcgis.Carto COM object that has been separated from its underlying RCW cannot be used. at ESRI.arcGIS.Carto.IFeatureLayer.Get_FeatureClass() at CopypasteTool.CopyPasteDocWin.list_FeatureSelection_SelectedIndexChanged(object sender, EventArgs e)

The key element of this error is of course:
"COM object that has been separated from its underlying RCW cannot be use"

This error occurs when I try to get the featureclass from a layer. The layer object is NOT null, and obtaining the featureclass elsewhere doesn't seem to cause a problem.


Has anyone else run into this error? Any strategies for resolving it?

Any help would be appreciated.
Thanks,
Mike
0 Kudos
3 Replies
MichaelRutkowski
Regular Contributor
Unfortunately, I'm working and calling everything from the main thread so this wouldn't be the issue.

The layer variable I am referencing is a global though.... the method that is causing trouble is called from inside an the active view's onselectionchanged event.

-Mike
0 Kudos
RichardWatson
Deactivated User
I assume that this is not occurring during ArcMap shutdown.  If it is then you need to explicitly say so.

Can you refetch/rediscover the layer you need?  Perhaps the layer you had is no longer valid?

Another possibility is that the object you are using is not valid because someone has called, correctly or incorrectly, a function which which destroys the underlying COM object.

You can debug this but doing so is going to be rather advanced.  I think that you would want to set a breakpoint on the functions that are called to do this.  There are several of this functions such as Marshal.ReleaseComObject, Marshal.FinalReleaseComObject, etc.  If you don't know how to do this then just ignore this comment.
0 Kudos