无法从Active Directory中读取所有用户-[DirectoryServicesCOMException] MoveNext()

问题描述 投票:1回答:1

我的团队正在使用用C#编写的程序来读取特定OU中的所有用户。该程序的行为非常奇怪。有时它工作了几个星期,然后在我们的广告或任何其他相关组件上没有任何大的变化,它引发了异常。然后它几周不工作,过了一段时间,它又开始正常运行。

代码

    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()

Data: System.Collections.ListDictionaryInternal
Error Code: -2147016672
Extended Error: 8431
Extended Error Message: 000020EF: SvcErr: DSID-020A07A7, problem 5012 (DIR_ERROR), data -1018
HResult: -2147016672
Message: An operations error occured.
Source: System.DirectoryServices
Stack Trace: at System.DirectoryServices.SearchResultCollection.ResultsEnumerator.MoveNext()
Target Site: Boolean MoveNext()

其他信息

  • 目标框架:.Net Framework 4.6.1(无其他库)
  • OU中的用户数量:432127
  • 程序在域控制器上执行
  • 加载第26932个用户后引发异常

我尝试过的

  • 我已经创建了一个循环来使用该工具的MoveNext()函数枚举器,发现它加载的结果达到特定元素,然后崩溃
  • 总是相同的元素
  • 在第一个例外之后,所有重试也会失败
  • 启动它的用户是域管理员(但我也已经使用企业管理员帐户尝试过,所以它是可能不是权限问题)
  • 我已删除发生异常时应读取的用户,但在下次运行时为先前的用户抛出了异常

我已经到了要解决这个问题的主意。非常感谢您的支持。

c# .net active-directory directoryservices directorysearcher
1个回答
0
投票

此答案只是用评论总结了我们的谈话。

[This thread部分匹配您得到的错误:

© www.soinside.com 2019 - 2024. All rights reserved.