I am trying to delete features from a feature class but i always get this error
"Error HRESULT E_FAIL has been returned from a call to a COM component."
at this line feature.Delete();
Here is my code:
private void DeleteRecordsFromStandardDBFeatureClass()
ESRI.ArcGIS.Geodatabase.IFeatureClass destinationFeatureClass = Globals.GlobalsInstance.StandardDB.GetFeatureWorkSpaceOfDataSource().OpenFeatureClass(m_tableName);
ESRI.ArcGIS.Geodatabase.IFeatureCursor searchCursor = destinationFeatureClass.Search(null, false);
// Delete the retrieved features.
ESRI.ArcGIS.Geodatabase.IFeature feature = null;
while ((feature = searchCursor.NextFeature()) != null)
catch (Exception ex)
Logger.LoggerInstance.LogError(ex.Message, DateTime.Now, "DeleteRecordsFromStandardDBFeatureClass", "MigrationFeatureClass", m_tableName);
throw new Exception(ex.Message);
I re-wrote the above code into an Add-in button that fetches the first featureclass in ArcMap's Table of Contents, and then creates a feature cursor, and then deletes all the features in the cursor (which ultimately deletes the features from the featureclass), but was unable to reproduce your error.
protected override void OnClick()
IMap map = ArcMap.Document.FocusMap;
IFeatureLayer featureLayer = map.get_Layer(0) as IFeatureLayer;
IFeatureClass featureClass = featureLayer.FeatureClass;
IFeatureCursor featureCursor = featureClass.Search(null, false);
while ((feature = featureCursor.NextFeature()) != null)
It is possible that you are receiving the error due to a lock issue. Make sure that no other instance of ArcMap or ArcCatalog has a lock on that feature class when you execute your code.