I'm attempting to query a feature class for all features that meet a certain criterion (in this case, the Status
field is NULL
). However, I'm not getting very far into the attempted method before ArcMap crashes completely. I have no reasonable idea on how to trace errors that cause a program crash, for starters, so I'm more confused than necessary, I expect. I'm building this in VS 2008 Express, for what it's worth.
public void PerformAttributeQuery(ESRI.ArcGIS.Geodatabase.IFeatureClass fc)
{
ESRI.ArcGIS.Geodatabase.IQueryFilter queryFilter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
queryFilter.WhereClause = "[Status] IS NULL"; // create the where clause statement
Everything is fine for that first couple of statements, but this query causes a crash:
// query the table passed into the function and use a cursor to hold the results
ESRI.ArcGIS.Geodatabase.IFeatureCursor featurecursor = fc.Search(queryFilter, false);
It crashes before reaching the next line (I put in debug message boxes for testing), but I'll put it here for propriety:
ESRI.ArcGIS.Geodatabase.IFeature feature = (ESRI.ArcGIS.Geodatabase.IFeature)featurecursor.NextFeature();
ESRI.ArcGIS.ArcMapUI.IContentsView currentContentsView = ArcMap.Document.CurrentContentsView as IContentsView;
ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = (ESRI.ArcGIS.Carto.IFeatureLayer)currentContentsView.SelectedItem;
ESRI.ArcGIS.Carto.IFeatureSelection fSelection = featureLayer as ESRI.ArcGIS.Carto.IFeatureSelection;
fSelection.Add(feature);
FindCommandAndExecute(ArcMap.Application as ESRI.ArcGIS.Framework.IApplication, "{AB073B49-DE5E-11D1-AA80-00C04FA37860}");
}
I cannibalized the PerformAttributeQuery
snippet to work with FeatureClasses instead of Tables (or so I had hoped), if you'd like a proper reference. My questions are:
- How can I get better reporting of crash errors?
- Where did I go wrong? Answer: I must shamefacedly admit that I used the wrong characters to denote the location of the feature table I was querying. Changing the
[Status]
in myqueryFilter.WhereClause
to\"Status\"
quite literally solved all obvious problems.
Best Answer
see code below
Note that sometimes useful exception messages can be embedded inside of a fairly cryptic general message, so it is important to examine InnerExceptions.