【发布时间】:2020-06-05 10:02:43
【问题描述】:
我的团队正在使用一个用 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(无其他库)
- 程序在域控制器上执行
我的尝试
- 我创建了一个循环来使用 枚举器并发现它将结果加载到特定的 元素然后崩溃
- 总是相同的元素
- 在第一次异常之后,所有重试也都失败了
- 启动它的用户是域管理员(但我 也用企业管理员账户试过,所以是 可能不是权限问题)
- 我已删除发生异常时应读取的用户,但在下一次运行时为前一个用户引发了异常
我已经到了一个点,我对解决这个问题没有更多的想法。感谢您的支持。
【问题讨论】:
-
请分享更多调试细节,例如强制异常的特定元素的特征、元素的数量以及所涉及的软件和库的版本。
-
你对这个特定元素的特征意味着什么?它是 System.DirectoryServices 命名空间中的 SearchResultCollection。您是在询问我加载的属性吗?
-
我不精通 Active Directory,但一般来说,如果某些东西 “加载 [..] 到特定元素然后崩溃” 有关该特定元素的更多详细信息可以协助其他用户尝试帮助您回答问题。
-
如果我删除了无法加载的用户,下次运行后将无法读取前一个用户。虽然,它可以在第一次运行时读取。
-
不幸的是,基于
ExtendedErrorMessage,我找不到任何有用的信息。我将使用异常的所有扩展信息更新问题。
标签: c# .net active-directory directoryservices directorysearcher