C# System.DirectoryServices.DirectoryServicesCOMException(0x8007202B):从服务器返回了引用

C# System.DirectoryServices.DirectoryServicesCOMException(0x8007202B):从服务器返回了引用,c#,active-directory,C#,Active Directory,尝试从Active Directory读取管理器的显示名称时,我收到异常(System.DirectoryServices.DirectoryServicesCOMException(0x8007202B):从服务器返回了引用) 异常快照: if (foundEntry.Properties["manager"] != null && foundEntry.Properties["manager"].Value != null) { DirectoryEntry grp

尝试从Active Directory读取管理器的显示名称时,我收到异常(System.DirectoryServices.DirectoryServicesCOMException(0x8007202B):从服务器返回了引用)

异常快照:

if (foundEntry.Properties["manager"] != null && foundEntry.Properties["manager"].Value != null)
{
    DirectoryEntry grp = new DirectoryEntry("LDAP://" + foundEntry.Properties["manager"].Value);
    if (grp != null && grp.Properties != null && grp.Properties["displayname"] != null && grp.Properties["displayname"].Value != null)
    {
        adresult.SupervisorName = grp.Properties["displayname"].Value.ToString();
    }
}

执行以下检查时发生异常

if (grp != null && grp.Properties != null && grp.Properties["displayname"] != null && grp.Properties["displayname"].Value != null)
代码:

if (foundEntry.Properties["manager"] != null && foundEntry.Properties["manager"].Value != null)
{
    DirectoryEntry grp = new DirectoryEntry("LDAP://" + foundEntry.Properties["manager"].Value);
    if (grp != null && grp.Properties != null && grp.Properties["displayname"] != null && grp.Properties["displayname"].Value != null)
    {
        adresult.SupervisorName = grp.Properties["displayname"].Value.ToString();
    }
}
集团财产

调试grp.Properties时,我看到以下内容:

我遗漏了什么吗?这个问题的原因可能是什么


非常感谢您的建议。

当您使用调试器时。。
grp.Properties以及grp.Properties[“displayname”]
的值是多少您熟悉
PrincipalContext
我已附上grp.Properties的屏幕截图。有什么建议吗?听起来您需要迭代DirectoryServices.PropertyCollection进行深入研究,以深入了解您需要的属性(乍一看),我认为您的
grp
没有正确填充。在调用
grp.RefreshCache()
之后创建
DirectoryEntry
时。看看这是否会给你带来任何错误。