我的团队正在使用用 C# 编写的程序来读取特定 OU 中的所有用户。该程序的行为非常奇怪。有时它工作了几个星期,然后对我们的 AD 或任何其他相关组件没有任何大的更改,它会引发异常。然后它不工作了几个星期,一段时间后它又开始正常运行。
代码
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
}
例外
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(无附加库)
- 该程序在域控制器上执行
我试过的
- 我创建了一个循环来使用枚举器的 MoveNext() 函数,发现它将结果加载到特定元素然后崩溃
- 它总是相同的元素
- 在第一个异常之后,所有重试也都失败了
- 启动它的用户是域管理员(但我也用企业管理员帐户尝试过,所以它可能不是权限问题)
- 我已经删除了发生异常时应该读取的用户,但是在下一次运行时,为以前的用户引发了异常
我已经到了一个点,我对解决这个问题没有更多的想法。感谢您的支持。