我正在尝试访问Active Directory,可以使用以下基本相同的代码在Visual Studio中成功完成此操作。但是,在使用Unity时,此行代码出现错误:“ DirectoryEntry ldapConnection = new DirectoryEntry(” xxxxxxx“);”
字符串用户名=“ xxxxx xxxxxxx”;
try
{
DirectoryEntry myLdapConnection = createDirectoryEntry();
DirectorySearcher search = new DirectorySearcher(myLdapConnection);
search.Filter = "(cn=" + username + ")";
SearchResult result = search.FindOne();
if (result != null)
{
print("user found");
}
else
{
print("user not found");
}
}
catch (Exception e)
{
print("Exception caught:" + e.ToString());
}
}
static DirectoryEntry createDirectoryEntry()
{
DirectoryEntry ldapConnection = new DirectoryEntry("xxxxxxx");
ldapConnection.Path = "LDAP://OU=xxxxxx,DC=xxxxxx,DC=xxxxx,DC=xxxxx";
ldapConnection.AuthenticationType = AuthenticationTypes.Secure;
return ldapConnection;
}
错误是:“ System.DirectoryServices.DirectoryEntry:.cctor()中的无效IL代码:方法主体为空。”
任何对此原因或可能的解决方案的帮助将不胜感激。