Skip to main content
 首页 » 编程设计

c#之-2147016672 "An operations error occured"System.DirectoryServices.AccountManagement

2024年02月24日18lexus

使用此代码

ArrayList myItems = new ArrayList(); 
UserPrincipal oUserPrincipal = GetUser(sUserName); 
 
PrincipalSearchResult<Principal> oPrincipalSearchResult = oUserPrincipal.GetGroups(GetPrincipalContext(sOU)); 
 
foreach (Principal oResult in oPrincipalSearchResult) 
{ 
    myItems.Add(oResult.Name); 
} 
return myItems; 

我收到错误 -2147016672“发生操作错误”,尝试用谷歌搜索但找不到任何答案。它发生在这条线上 oUserPrincipal.GetGroups(GetPrincipalContext(sOU)) 但它继续到 foreach 并且不会抛出任何错误并继续但是如果你不放置 try and catch 那么它会向你显示异常。有什么想法吗?

附加信息

如果我在不传递 OU 的情况下使用 oUserPrincipal.GetGroups() 添加到其中,一切正常。

请您参考如下方法:

这看起来像是一个访问权限问题,尝试实例化一个新的 PrincipalContext 时尝试更改上下文选项