I'm not actually sure whether this is a VB.net problem or an ESRI problem...but given the number of really odd ESRI quirks I've encountered, my money's on the latter...
I have a piece of code in an Add-In toolbar that creates an update cursor from a spatial query and cycles through the results checking feature length and deleting features below a certain threshold. I don't think that's too relevant, but just in case...
My problem is that when I run the code independently of the IDE (i.e., just from ArcMap) OR when I run the code from the IDE (Debug-->Start Debugging) without breakpoints, this block of code does not execute. If, however, I place a breakpoint after the cursor is retrieved and run the code from the IDE, this block of code executes just fine. The results are HUGELY different depending on whether I've put a breakpoint there or not.
Has anyone encountered a situation like this? Any ideas of what I might be doing wrong? I've tried deleting the add-in, cleaning the solution, restarting my computer, and rebuilding, and it does not help.
Edit: Here's the code block:
curSubs = fcSubBasin.Update(Nothing, False) pComReleaser2.ManageLifetime(curSubs) ftrSub = curSubs.NextFeature Dim pOutline As ESRI.ArcGIS.Geometry.IPolyline, pTopoOper As ESRI.ArcGIS.Geometry.ITopologicalOperator Do While Not ftrSub Is Nothing Using pComReleaser3 As New ESRI.ArcGIS.ADF.ComReleaser curStreams = modUtilities.PerformSpatialQuery(fcStreams, ftrSub.Shape, ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelContains) pComReleaser3.ManageLifetime(curStreams) 'figure out which is the longest pDataStats = New ESRI.ArcGIS.Geodatabase.DataStatistics pDataStats.SimpleStats = True pDataStats.Field = strLengthFld pDataStats.Cursor = curStreams pStats = pDataStats.Statistics dblMaxLength = pStats.Maximum curStreams = Nothing End Using Using pComReleaser3 As New ESRI.ArcGIS.ADF.ComReleaser 'first, delete all straggler segments - little bits of stream that are a result of the delineated boundary not perfectly matching 'the nodes of the stream network curStreams = modUtilities.PerformSpatialQuery(fcStreams, ftrSub.Shape, ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelContains, method:="Update") pComReleaser3.ManageLifetime(curStreams) ftrStream = curStreams.NextFeature Do Until ftrStream Is Nothing 'only keep the feature if it's the max length we just figured out If ftrStream.Value(intLengthFld) < dblMaxLength Then curStreams.DeleteFeature() End If ftrStream = curStreams.NextFeature Loop curStreams = Nothing End Using Using pComReleaser3 As New ESRI.ArcGIS.ADF.ComReleaser 'next, delete any segments that happen to coincide perfectly with the subwatershed boundaries; they were created by intersect but would 'not have been caught by the polygon contains above pTopoOper = TryCast(ftrSub.Shape, ESRI.ArcGIS.Geometry.ITopologicalOperator) If Not pTopoOper Is Nothing Then pOutline = pTopoOper.Boundary curStreams = modUtilities.PerformSpatialQuery(fcStreams, pOutline, ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelContains, method:="Update") pComReleaser3.ManageLifetime(curStreams) ftrStream = curStreams.NextFeature Do Until ftrStream Is Nothing 'delete any stream segments that coincide with the subwatershed boundary curStreams.DeleteFeature() ftrStream = curStreams.NextFeature Loop curStreams = Nothing End If ftrSub = curSubs.NextFeature End Using Loop curSubs = Nothing
REVISED INFORMATION: After further investigation I've discovered that what's actually happening is that while I'm stepping through the debugger, the spatial query works properly. When I am not stepping through the debugger, it does not. I am using ESRI's spatial query snippet as below (with very small tweaks), passing relation 'contains' to select line segments that are within polygons. The line feature class is the result of an intersection with the polygon feature class immediately prior to this, so all lines should fall within a polygon. However, when I am not stepping through with the debugger, several of the lines are not selected. Does this clarification offer any additional ideas?
Public Function PerformSpatialQuery(ByVal featureClass As ESRI.ArcGIS.Geodatabase.IFeatureClass, _ ByVal searchGeometry As ESRI.ArcGIS.Geometry.IGeometry, _ ByVal spatialRelation As ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum, _ Optional ByVal whereClause As System.String = "", _ Optional ByVal method As String = "Search") As ESRI.ArcGIS.Geodatabase.IFeatureCursor ' create a spatial query filter Dim spatialFilter As ESRI.ArcGIS.Geodatabase.ISpatialFilter = New ESRI.ArcGIS.Geodatabase.SpatialFilterClass() ' specify the geometry to query with spatialFilter.Geometry = searchGeometry ' specify what the geometry field is called on the Feature Class that we will be querying against Dim nameOfShapeField As System.String = featureClass.ShapeFieldName spatialFilter.GeometryField = nameOfShapeField ' specify the type of spatial operation to use spatialFilter.SpatialRel = spatialRelation ' create the where statement If whereClause <> "" Then 'added the 'optional' in the function statement and this if-then to make the whereClause optional spatialFilter.WhereClause = whereClause End If ' perform the query and use a cursor to hold the results Dim featureCursor As ESRI.ArcGIS.Geodatabase.IFeatureCursor If String.Equals(method, "Search", StringComparison.CurrentCultureIgnoreCase) Then featureCursor = featureClass.Search(spatialFilter, False) Else featureCursor = featureClass.Update(spatialFilter, False) End If Return featureCursor End Function