17
我試圖讓所有Active Directory組的用戶,用下面的代碼:UserPrincipal.GetGroups失敗,未知錯誤
private static IEnumerable<string> GetGroupNames(string userName)
{
using (var context = new PrincipalContext(ContextType.Domain))
{
using (var userPrincipal = UserPrincipal.FindByIdentity(context, userName))
{
var groupSearch = userPrincipal.GetGroups(context);
var result = new List<string>();
foreach (var principal in groupSearch)
{
Log.LogDebug("User {0} is member of group {0}", userPrincipal.DisplayName, principal.DisplayName);
result.Add(principal.SamAccountName);
}
return result;
}
}
}
此代碼正確地找到用戶主體,但是當GetGroups被調用失敗一個PrincipalOperationException:未知的錯誤(0x80005000)。
根異常:
at System.DirectoryServices.AccountManagement.ADStoreCtx.GetGroupsMemberOf(Principal foreignPrincipal, StoreCtx foreignContext)
at System.DirectoryServices.AccountManagement.Principal.GetGroupsHelper(PrincipalContext contextToQuery)
at System.DirectoryServices.AccountManagement.Principal.GetGroups(PrincipalContext contextToQuery)
at [line of the GetGroup call]
內部異常(收到COMException):
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_AdsObject()
at System.DirectoryServices.PropertyValueCollection.PopulateList()
at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
at System.DirectoryServices.PropertyCollection.get_Item(String propertyName)
at System.DirectoryServices.AccountManagement.ADUtils.RetriveWkDn(DirectoryEntry deBase, String defaultNamingContext, String serverN
Another report with this problem。
任何線索?
這是否發生在所有用戶?或者它只發生在一個特定的用戶?我知道.NET庫中存在一個錯誤,當用戶DN包含「/」時,它會引發此COMException。如果您確認這種情況只發生在僅包含「/」的DN的用戶身上,我也對此問題進行了修復。 – 2010-12-24 07:32:11
我遇到您描述的問題。當用戶DN包含「/」時,我遇到問題。你能告訴我你使用的修復程序是什麼? – Lamelas84 2017-01-31 09:04:31