I am trying to get back a list of ObjectIDs from a selection set using VB.Net in ArcObjects for ArcGIS Desktop 9.3. I have been passing an object populated using the ".IDs" method from the ISelectionSet interface ((which returns an IEnum2 object with the OBJECTIDS for the selected features) to the following function:

    Public Function iterateOIDS(ByRef OID_Enumerator As ESRI.ArcGIS.Geodatabase.IEnumIDs)
    Dim itemID As  = OID_Enumerator.Next()
    Dim listofOIDS As List(Of Integer)

    Do While itemID <> -1
        itemID = OID_Enumerator.Next()


    Return listofOIDS

End Function

However, this crashes ArcGIS and results in Visual Studio throwing an LoaderLock error, if its in Debug Mode. The offending piece of code is apparently the "listofOIDs.Add(itemID)" inside the While Loop.

What am I doing wrong? Any light that anyone can shed on this problem would be awesome!


2 Answers 2


Seems like you have not initialized the list using New.

Dim listofOIDS As New List(Of Integer)

  • Unfortunately, this didn't solve the problem. I used a try/catch block around the problem code to see if I could get a more specific error message, which reported a "Conversion from type list(of String) to type String is not valid," which makes no sense. Also the "Immediate Window" in Visual Basic has an error as follows: "A first chance exception of type 'System.InvalidCastException' occured in Microsoft.VisualBasic.dll."
    – Turbo
    Commented Sep 16, 2014 at 4:42

I figured it out. I was trying to add the returned list (the 'listofOIDs') to another outside list along these lines:


instead of:

currentResults.ListOfOIds = iterateTheOIDs(selectionSet.IDs)

which would have created a list inside of a list (a list-ception, perhaps?)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.