Since posting this question, I've come to the conclusion I'm not fighting flaws in the BasicGeoprocessor object, but more likely having issues with poor object lifecycle management on my part (there is some helpful info cited by @blah238 in this thread).
I accepted @Jakub's answer to close the question so it won't appear in the unanswered questions list perpetually. However, at present I believe there's nothing wrong with my BasicGeoprocessor implementation, and the issue is related to hanging references elsewhere in my code.
I maintain a small ArcObjects solution using the 9.2 SDK
that is plagued by inconsistent failures in its . It seems to be failing more frequently than it succeeds. While it succeeds on every first run, it tends to fail on subsequent attempts. Although, sometimes it still works on the second run, so it's been difficult to truly isolate the cause of errors.
I'd certainly rather use this approach and apply the Geoprocessor, but it can only do wholesale intersections at the shapefile level, and I only want to intersect two in-memory
SelectionSet objects. Could the
ITopologicalOperator do this? In the past I've been unable to make it work on real-world data, and it seems some others have too.
Here's the relevant block of code calling the
BasicGeoprocessor. It's argument variables are explained in the comments, and if you follow the link above, you can see the example it's patterned after. I suspect my references to either
parcelFCursor may be lingering between calls, creating the errors.
'perform intersection Dim BGP As IBasicGeoprocessor BGP = New BasicGeoprocessor BGP.SpatialReference = parcelFeature.Shape.SpatialReference Try 'THE VARS ARE AS FOLLOWS. THEY ALWAYS LOOK GOOD IN THE DEBUGGER: ' parcelTable and soilTable are ITable ' True (useSelectedInput argument) ' True (useSelectedOverlay argument) ' 0.0# (the mythical Tolerance value, I've also tried 0.0, and 0) ' pFCN (IFeatureClassName) intersectFC = BGP.Intersect(parcelTable, True, soilTable, True, 0.0#, pFCN) Catch ex As Exception MsgBox("unable to intersect input data") Exit Sub End Try '(blah238's answer, first link above, suggests this is **NOT** the way to do this) 'Clean up. This chunk shows all the variables preceding the Try block, too. parcelLayer = Nothing 'IFeatureLayer parcelFC = Nothing 'IFeatureClass parcelFeatSel = Nothing 'IFeatureSelection parcelSelSet = Nothing 'ISelectionSet parcelFCursor = Nothing 'IFeatureCursor parcelFeature = Nothing 'IFeature parcelTable = Nothing 'ITable <--- I think this one is the culpret. parcelSF = Nothing 'ISpatialFilter soilLayer = Nothing 'FeatureLayer soilFC = Nothing 'IFeatureClass soilSelSet = Nothing 'ISelectionSet soilTable = Nothing 'ITable <--- and or this one. pWSN = Nothing 'IWorkSpaceName pFCN = Nothing 'IFeatureClassName pDSN = Nothing 'IDataSetName intersectFC = Nothing 'IFeatureClass BGP = Nothing 'IBasicGeoprocessor
I'd love to know what other folks are doing to perform in-memory intersection on
SelectionSet objects or if anything stands out as obviously wrong here. As always, thanks so much for any assistance and insights you have.