locked
Cannot read all users from Active Directory - [DirectoryServicesCOMException] MoveNext() RRS feed

  • Question

  • User1829539592 posted

    Hello,

    my team is using a program written in C# to read all users from a specific OU. The program behaves very strange. Sometimes it is working for a couple of weeks and then without any big changes on our AD or any other related component, it throws an exception. Then it is not working for a couple of weeks and after some time it start to run normally again.

    Code

    DirectoryEntry searchRoot = new DirectoryEntry("<LDAP string>")
    
    searchRoot.AuthenticationType = AuthenticationTypes.None;
    DirectorySearcher search = new DirectorySearcher(searchRoot);
    
    search.Filter = <our filter>;
    search.PropertiesToLoad.Add("<some property>");
    search.PageSize = 1;
    
    SearchResult result;
    SearchResultCollection resultCol = null;
    
    try
    {
      resultCol = search.FindAll();
    }
    catch (Exception ex)
    {
      Console.WriteLine(ex.ToString());
    }
    
    if (resultCol != null)
    {
      Console.WriteLine("Result Count: " + resultCol.Count); //.Count throws the Exception
    }

    Exception

    Unhandled Exception: System.DirectoryServices.DirectoryServicesCOMException: An operations error occurred.
    
      at System.DirectoryServices.SearchResultCollection.ResultsEnumerator.MoveNext()
      at System.DirectoryServices.SearchResultCollection.get_InnerList()
      at System.DirectoryServices.SearchResultCollection.get_Count()

    Additional Information

    • I have created a loop to use the MoveNext() function of the enumerator and found out that it loads results up to a specific element and then crashes
    • It is always the same element
    • After the first exception all retries fail as well
    • The program is executed on a domain controller
    • The user that starts it is a domain admin (but I have also tried it with an enterprise admin account, so it is probably not a permission issue)

    I have come to a point, where I have no more ideas on solving this problem. I would appreciate all your support.

    Thanks in advance
    Jan

    Friday, June 5, 2020 9:36 AM

All replies

  • User1829539592 posted

    Dear admins,

    can you please delete this thread? I couldn't find any button to do it myself. While I was waiting for approval, a Stackoverflow user helped me to find a solution.

    Thanks

    Monday, June 8, 2020 6:54 AM