Hello,
What I'm doing is really straight forward. In my Add-In extension, I simply create a new file geodatabase and a new feature class, and insert point features for a list of lat/longs using feature buffer. However, ArcMap creashes right on featureCursor.InsertFeature(featureBuffer). I'm using ArcMap 10.4.1. Any idea would be greatly appreciated.
private void AddNewTrackingPoints(IFeatureClass featureClass, List<TrackingRecord> trackingRecords)
{
IDataset dataset = (IDataset)featureClass;
IWorkspace workspace = dataset.Workspace;
IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace;
workspaceEdit.StartEditing(false);
workspaceEdit.StartEditOperation();
// Create the feature buffer.
IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
// Create insert feature cursor using buffering.
IFeatureCursor featureCursor = featureClass.Insert(true);
try
{
foreach (TrackingRecord record in trackingRecords)
{
Point p = new PointClass();
p.PutCoords(record.Longitude, record.Latitude);
// Set the feature buffer's shape and insert it.
featureBuffer.Shape = p;
System.Reflection.PropertyInfo[] props = record.GetType().GetProperties();
foreach (System.Reflection.PropertyInfo prop in props)
{
int fieldIndex = featureClass.FindField(prop.Name);
featureBuffer.set_Value(fieldIndex, prop.GetValue(record));
}
featureCursor.InsertFeature(featureBuffer); //ArcMap creashes here
}
// Attempt to flush the buffer.
featureCursor.Flush();
}
catch (COMException comExc)
{
// Handle the error in a way appropriate to your application.
}
finally
{
// Release the cursor as it's no longer needed.
Marshal.ReleaseComObject(featureCursor);
}
workspaceEdit.StopEditOperation();
workspaceEdit.StopEditing(true);
}
Solved! Go to Solution.
Turns out is a threading issue. The method is called by a timer method. Calling it from a extension's method fixed the problem.
Could it be license issue? I'm using ESRI's home program.
Turns out is a threading issue. The method is called by a timer method. Calling it from a extension's method fixed the problem.