Upgrade Code to ArcGIS 10 / ArcObjects in VS2010 IFeatureCursor Com Exception

Discussion created by smccle on Jan 6, 2012
Latest reply on Jan 8, 2012 by Hornbydd
I'm currently trying to get a tool I did not originally write upgraded to run in ArcGIS 10.  I'm unsure of the original version of ArcGIS ArcObjects the code used, but I think it was 9.1.  The code broke after 9.3 SP1 (to the best of my knowledge).   I upgraded the code into VS2010 and reset all the libraries and compiled with no errors.  However, when I run the code I'm getting a com exception seemingly random when I use .NextFeature on a search cursor.

Basically the code takes a selected route and makes sure it is not part of a larger route system (i.e. multiple chunks of geometry), if it is it makes a temp polyline and combines all the chunks into a single polyline.  Then the code iterates through each vertex and searches for a match on equations along the route (stored in a separate point FC) and/or measures along the route (again in a separate FC).  It breaks the polyline back up based on the results and re-applys M values.  In a nutshell the tool re-measures routes that have equations or multiple measures.

Basically the code fails on random vertexes with a com exception at the pEquationFeature = pEquationCursor.NextFeature line.

A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in WYDOTRts.dll
Error measuring route:  The index passed was not within the valid range. (from the COM err desription)

'Test for equation.
                        Dim pEquationCursor As IFeatureCursor
                        pHitTest = pPC.Point(j)
                        pEquationCursor = pEquationsFLayer.Search(pEquationFilter, True)
                       pEquationFeature = pEquationCursor.NextFeature
                        pIsOnEquation = False
                        Do While Not pEquationFeature Is Nothing
                            pEquationPoint = pEquationFeature.Shape
                            pIsOnEquation = pHitTest.HitTest(pEquationPoint, 0.1, esriGeometryHitPartType.esriGeometryPartVertex, Nothing, DblHitDis, LngPrtIdx, LngSegIdx, False)
                            If pIsOnEquation Then Exit Do
                            pEquationFeature = pEquationCursor.NextFeature

The measures search cursor is much the same, but I never get that far.....I'm leaving this job next week for a new job and I'd sure like to get my employer up to ArcGIS 10 before I leave, but this tool is a must have! 


Susan McClendon