UserPrincipal.GetAuthorizationGroups抛出异常

时间:2013-05-02 22:10:06

标签: .net

在以下代码中

PrincipalContext* context = new PrincipalContext(ContextType::Domain, domainName);
UserPrincipal* user = UserPrincipal::FindByIdentity(context, IdentityType::SamAccountName, userName);
PrincipalSearchResult<Principal*>* groups = user->GetAuthorizationGroups();

我得到以下异常:

  

消息:对象引用未设置为对象的实例。

异常调用堆栈:

 at System.DirectoryServices.AccountManagement.Principal.CheckDisposedOrDeleted()
 at System.DirectoryServices.AccountManagement.UserPrincipal.GetAuthorizationGroupsHelper()
 at System.DirectoryServices.AccountManagement.UserPrincipal.GetAuthorizationGroups()

知道内部方法失败的原因吗?如何删除或处置用户,或者发生了什么?

0 个答案:

没有答案