2

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
spearman
  • 21
  • 3
  • Just to clarify - you're NOT sure if the exception is being thrown on the .Search line? If you can't debug it live, can you comment out most of it and then progressively un-comment lines until it throws errors? Alternatively, you should probably check that provCursor is not Nothing before trying to use it. – Juffy Nov 11 '12 at 00:19
  • Thanks for the comment. I'd done commenting and then uncommenting lines to debug. The exception is really thrown in the Search line. I'd checked if provCursor Is Nothing but it always is Nothing so I'm unable to Search. The "Variable 'provCursor' is passed by reference before it has been assigned a value. A null reference exception could result at runtime." error persists. – spearman Nov 21 '12 at 09:19

1 Answers1

0

Try:

pSelSet.Search(spatialFilter, True, out provCursor)
Cerbrus
  • 70,800
  • 18
  • 132
  • 147