遍历属性时,ActiveDirectory错误0x8000500c

jga*_*fin 5 c# directoryservices active-directory

我得到了以下代码段(SomeName/ SomeDomain在我的代码中包含实际值)

var entry = new DirectoryEntry("LDAP://CN=SomeName,OU=All Groups,dc=SomeDomain,dc=com");
foreach (object property in entry.Properties)
{
    Console.WriteLine(property);
}
Run Code Online (Sandbox Code Playgroud)

它为前21个属性打印OK,但随后失败:

COMException {"Unknown error (0x8000500c)"}
   at System.DirectoryServices.PropertyValueCollection.PopulateList()
   at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
   at System.DirectoryServices.PropertyCollection.PropertyEnumerator.get_Entry()
   at System.DirectoryServices.PropertyCollection.PropertyEnumerator.get_Current()
   at ActiveDirectory.Tests.IntegrationTests.ObjectFactoryTests.TestMethod1() in MyTests.cs:line 22
Run Code Online (Sandbox Code Playgroud)

为什么?我该怎样预防呢?

更新

这是一个失败的自定义属性.

我试图使用entry.RefreshCache()entry.RefreshCache(new[]{"theAttributeName"})枚举属性(没有帮助)前.

UPDATE2

entry.InvokeGet("theAttributeName")工作(和没有RefreshCache).

有人可以解释原因吗?

UPDATE3

如果我向项目提供FQDN,它可以工作: LDAP://srv00014.ssab.com/CN=SomeName,xxxx

赏金

我正在寻找解决以下问题的答案:

  • 为什么entry.Properties["customAttributeName"]在提到的例外情况下失败
  • 为何entry.InvokeGet("customAttributeName")有效
  • 异常的原因
  • 如何兼顾两者

Chr*_*ler 4

如果想要从不属于自定义属性所在域的计算机访问自定义属性(登录用户的凭据无关紧要),则需要传递正在尝试的对象的完全限定名称访问,否则客户端计算机上的架构缓存不会正确刷新,不用介意您进行的所有 schema.refresh() 调用

在这里找到的。鉴于对问题的更新,这听起来像是您的问题。