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

I am building a tool in my Add-in that is partially based on a .Net sample and partially on my former VBA tool. (Both work)

My problem is that I would like to be able to only select features from the current layer in the TOC. For this i have to use iFeatureSelection:SelectFeatures with iSpatialFilter. This works flawlessly in VBA but not in my .Net Add-in

ArcMap crashes when I refresh / partial refresh the map.

Any ideas?

pGeoFeatureLayer.Selectable = True

pFeatureSelection = pGeoFeatureLayer

pEnv = m_pFeedbackEnv.Stop()

With pSpatialFilter
    .GeometryField = "Shape"
    .Geometry = pEnv
    .SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects
End With

If Not arg.Shift Then
    pFeatureSelection.SelectFeatures(pSpatialFilter, ESRI.ArcGIS.Carto.esriSelectionResultEnum.esriSelectionResultNew, False)
    pFeatureSelection.SelectFeatures(pSpatialFilter, ESRI.ArcGIS.Carto.esriSelectionResultEnum.esriSelectionResultAdd, False)
End If

m_focusMap.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)
share|improve this question
up vote 4 down vote accepted

Hard to tell from the incomplete code sample, but I get the impression ArcMap crashes because of an unhandled exception in your .NET code. I suggest catching the exception to find out what error is actually ocurring.

Assuming the last line is the place your code crashes, I guess it could probably be a NullRefenceException when calling PartialRefresh method on the (possibly null) m_focusMap object.

EDIT: As discussed in the comments below, the issue was that the display feedback needs to be canceled before refreshing the active view.

share|improve this answer
Cannot trap the error; application crashes on the refresh line. m_focusMap is not null. dll compiles without errors. ArcMap crashed with the compiled add-in as well as when debugging – Jakub Oct 28 '10 at 14:50
Does it also crash without the prior call to SelectFeatures? – Petr Krebs Oct 28 '10 at 14:54
I should add that when using the FocusMap.SelectByShape method, everything works fine. It's only when i try to select featues from a specific layer via iFeatureSelection:SelectFeatures when i encounter the crash. (Envelope geometry passed into the spatial filter is not null or empty, the same spatial filter successfully returns feature count from the underlying feature class) – Jakub Oct 28 '10 at 14:58
crashes on this line:m_focusMap.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSe‌​lection, Nothing, Nothing) Also crashes with the full refresh method: m_focusMap.Refresh – Jakub Oct 28 '10 at 14:59
Ok, this is when hunting for errors like this becomes a trial-and-error :-) First, I would try without the display feedback as this is most likely to be a display-related issue. Second, try calling IFeatureSelection.SelectionChanged after altering the selection, but I do not think it will help... Third, I have no other idea :-) – Petr Krebs Oct 28 '10 at 15:06

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.