Arcobjects add-in stops working with no apparent error

المشرف العام

Administrator
طاقم الإدارة
I am developing a simple add-in that will trigger an action after user selects features on the map (the action will essentially make sure a dockable window is open and in that window display information about the selected features).

I have implemented a simple function that loops over selected features using IEnumFeature and collects their OIDs. To make sure the OIDs are present for all features in the selection, I set the IEnumFeatureSetup.AllFields = true.

Now to the problem. After I've selected a number features several times (regardless of what features or how many I select), the SelectionChanged event stops from being fired. It appears as if the add-in has crashed, but no error message is displayed. This happens both in debug and production. If I try to restart the add-in by de-selecting it in the Customise - Extensions menu, I can no longer select it back. ArcMap works fine otherwise. To get the add-in to work again I must restart ArcMap.

The features come from a file geodatabase. They have 5 short text fields each and there is around 1300 of them. The more features I select at once, the less rounds of feature selection it takes for the add-in to crash.

Unlike in ArcGIS crashes with no error number in Visual Studio I get no ArcGIS error or exception!

I am developing in Arcobjects 10.1 SDK with Visual Studio 10 for C# Express using .NET 3.5. I cannot upgrade nor can I use .NET 4.0 due to client constraints. The add-in is being tested in ArcMap 10.1.

private void SelectionChanged_Handler() { List locodes = new List(); try { ISelection selection = ArcMap.Document.FocusMap.FeatureSelection; IEnumFeature featuresEnum = (IEnumFeature)selection; IEnumFeatureSetup featureSetup = (IEnumFeatureSetup)selection; featureSetup.AllFields = true; IFeature feature; while ((feature = featuresEnum.Next()) != null) { int locodeFldID = feature.Fields.FindField("locode"); string locode = feature.get_Value(locodeFldID).ToString(); locodes.Add(locode); // Release feature object Marshal.FinalReleaseComObject(feature); } // Release IEnum reference Marshal.FinalReleaseComObject(featuresEnum); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } }}Why is the add-in crashing (stopping to work) without apparent error. Might this be related to resources not being freed correctly?



أكثر...
 
أعلى