I have the following code that is retrieving user attributes from active directory bades on a usergroup name. I am getting the error "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index" after some atrributes are returned even though there are several users in the group . IN this example I got 2 different users then the error was returned. What would be causing this to error out after returning some data.
Dim empattributes2 As New EmpAttributes
Dim groupname As String = "admins"
Dim rootEntry As New DirectoryEntry("GC://**=**,dc=cits,***=***,dc=com")
Dim searcher As New DirectorySearcher(rootEntry)
searcher.Filter = "(&(objectCategory=user)(memberOf=CN=" & groupname & ",OU=**,OU=**,DC=***,DC=***,DC=com))"
Dim results As SearchResultCollection
results = searcher.FindAll()
Dim result As SearchResult
For Each result In results
Dim Empname As String = (result.Properties("sn")(0))
empattributes2 = GetUserAttr(Empname)
lblMsg.Text = empattributes2.EmpID & " " & empattributes2.showname & " " & empattributes2.emailaddress & " " & empattributes2.GroupMember & " " & empattributes2.uDepartment & " " & empattributes2.uManager & " " & empattributes2.uPhone & " " & empattributes2.UserID & " " & empattributes2.uTitle