Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

During development of ArcGis AddIn I've found strange behaviour of MapSelection when there are a lot of selected features. When I tryed to get selected features I've received duplicate features. So the code below throws an exception "Key already exist" . I have no idea why this happens and how to fix it. Can anybody hekp me?

  IEnumFeature enumFeat = (IEnumFeature) ArcMap.Document.FocusMap.FeatureSelection;
  IEnumFeatureSetup enumSetup = (IEnumFeatureSetup)enumFeat;
  enumSetup.AllFields = true;
  IDictionary<int, int> dicIds = new Dictionary<int, int>();
  while ((feat = enumFeat.Next()) != null)
    dicIds.Add(feat.OID, num);
share|improve this question
Are you sure all the selected features come from the same layer? The help doc says "Because IEnumFeature works with all the FeatureLayers, you cannot use it to loop through the features belonging to just one FeatureLayer." The same OID might be used by features in different layers. – Kirk Kuykendall Dec 9 '12 at 20:38

The Line:

  IEnumFeature enumFeat = (IEnumFeature) ArcMap.Document.FocusMap.FeatureSelection;

gets all the selected features in the map, across all layers. This is where you getting duplicate OID's, since they are coming from features in different Layers.

You should use the IFeatureSelection Interface instead. Get the selectionset using the IFeatureSelection.SelectionSet Property, and then you can iterate over selected features in a particular layer.

share|improve this answer
Hi! Thank you. I'll try IFeatureSelection interface. I'm absolutely sure that I've selected features from only one layer. This code is just for testing purposes there is a check in production, which layer feature belongs to . – megadrofan Dec 11 '12 at 21:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.