ArcMap crashes when inserting new feature into file geodatabase

1289
2
Jump to solution
07-25-2016 09:34 AM
LimingWu
New Contributor II

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);

        }

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LimingWu
New Contributor II

Turns out is a threading issue. The method is called by a timer method. Calling it from a extension's method fixed the problem.

View solution in original post

0 Kudos
2 Replies
LimingWu
New Contributor II

Could it be license issue? I'm using ESRI's home program.

0 Kudos
LimingWu
New Contributor II

Turns out is a threading issue. The method is called by a timer method. Calling it from a extension's method fixed the problem.

0 Kudos