我正在尝试从不同的域获取用户详细信息,但它会引发以下错误:
An exception of type 'System.Runtime.InteropServices.COMException' occurred in System.DirectoryServices.dll but was not handled in user code
代码如下:
// Getting domain
var context = new DirectoryContext(DirectoryContextType.Domain, "alpha");
Domain domain = Domain.GetDomain(context);
using (DirectorySearcher searcher = new DirectorySearcher())
{
var de = new DirectoryEntry(domain.Name);
searcher.SearchRoot = de;
searcher.SearchScope = SearchScope.Subtree;
searcher.PropertiesToLoad.Add("sAMAccountName");
searcher.Filter = string.Format("(&(objectClass=user)(sAMAccountName={0}))", "myusername");
// *** ERROR HERE ***
var results = searcher.FindAll();
}
我已经尝试以域管理员身份运行 Visual Studio,但没有运气。
提前致谢。