I have a QC process that runs through some data, flags various features, and then I want it to write them out to a new database with an exact copy of the feature class (I can't copy the feature class completely, because not all of the features are flagged). My code for flagging the data works fine, but when I go to insert my created feature buffer I get a vague COM Exception. I've read that these errors usually occur with field/field value errors, but I've used a IFieldChecker, which reports no errors. And I've gone through the created feature class fie and the values in the featureusing (ComReleaser comReleaser = new ComReleaser()) { IFeatureCursor featuresToCopy = fc.Search(qf, true); comReleaser.ManageLifetime(featuresToCopy); IFeature currFeat = featuresToCopy.NextFeature(); IFeatureCursor insertCursor = newFC.Insert(true); comReleaser.ManageLifetime(insertCursor); while (currFeat != null) { IFeatureBuffer featBuff = newFC.CreateFeatureBuffer(); // Add the original feature's geometry to the feature buffer. featBuff.Shape = currFeat.Shape; // Add all the original feature's fields to the feature buffer AddFieldsToFeatureBuffer(ref featBuff, currFeat); try { insertCursor.InsertFeature(featBuff); } catch { throw; } currFeat = featuresToCopy.NextFeature(); } } //This code was taken right from here private void AddFieldsToFeatureBuffer(ref IFeatureBuffer featBuffer, IFeature feature) { // Copy the attributes of the orig feature the new feature IRowBuffer rowBuffer = (IRowBuffer)featBuffer; IFields fieldsNew = rowBuffer.Fields; IFields fields = feature.Fields; for (int i = 0; i <= fields.FieldCount - 1; i++) { IField field = fields.get_Field(i); if ((field.Type != esriFieldType.esriFieldTypeGeometry) && (field.Type != esriFieldType.esriFieldTypeOID)) { int intFieldIndex = fieldsNew.FindField(field.Name); if (intFieldIndex != -1) { try { var value = feature.get_Value(i); featBuffer.set_Value(intFieldIndex, value); } catch (Exception ex) { WriteError(ex); } } } } }
Also, I'm not sure if it is related, but when I am debugging the code the execute function to check the members of the insert cursor does not work. I am assuming it's because the cursor has an exclusive lock on the data.