I am trying to create a custom tool in VB.Net for arcmap. But im having a problem with FeatureCursor passed to ISelectionSet's Search() method.
Here's a portion of my code:
Dim pSelSet As ISelectionSet = provFSel.SelectionSet
Dim provCursor As IFeatureCursor
pSelSet.Search(spatialFilter, True, provCursor)
Dim provFeature As IFeature = provCursor.NextFeature
A blue squiggle appears under provCursor inside Search() that says "Variable 'provCursor' is passed by reference before it has been assigned a value. A null reference exception could result at runtime." Ive tried
Dim provCursor As IFeatureCursor = New FeatureCursor
but a squiggle under New FeatureCursor says "'ESRI.ArcGIS.Geodatabase.FeatureCursorClass.Friend Sub New()' is not accessible in this context because it is 'Friend'.". I also tried
Dim provCursor As IFeatureCursor = Nothing
but with no success.
In all my debugging attempts, Arcmap crashed with this error: A first chance exception of type 'System.NullReferenceException' occurred in Microsoft.VisualBasic.dll
Can somebody help me figure out whats wrong with my code? Ill really appreciate any help.
-spearman
Im not actually sure if error occurs in the above codes or in the prior codes. Im therefore posting the whole subprocedure content:
Dim pPoint As IPoint = pMxDoc.CurrentLocation
Dim provFSel As IFeatureSelection = provinceLayer
Dim pGeom As IGeometry = pPoint.Shape
Dim spatialFilter As ISpatialFilter = New SpatialFilter
With spatialFilter
.Geometry = pGeom
.SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin
End With
Dim pSelSet As ISelectionSet = provFSel.SelectionSet
Dim provCursor As IFeatureCursor
pSelSet.Search(spatialFilter, True, provCursor)
Dim provFeature As IFeature = provCursor.NextFeature