簡體   English   中英

遍歷屬性時,ActiveDirectory錯誤0x8000500c

[英]ActiveDirectory error 0x8000500c when traversing properties

我得到了以下代碼段( SomeName / SomeDomain在我的代碼中包含實際值)

var entry = new DirectoryEntry("LDAP://CN=SomeName,OU=All Groups,dc=SomeDomain,dc=com");
foreach (object property in entry.Properties)
{
    Console.WriteLine(property);
}

它為前21個屬性打印OK,但隨后失敗:

COMException {"Unknown error (0x8000500c)"}
   at System.DirectoryServices.PropertyValueCollection.PopulateList()
   at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
   at System.DirectoryServices.PropertyCollection.PropertyEnumerator.get_Entry()
   at System.DirectoryServices.PropertyCollection.PropertyEnumerator.get_Current()
   at ActiveDirectory.Tests.IntegrationTests.ObjectFactoryTests.TestMethod1() in MyTests.cs:line 22

為什么? 我該怎樣預防呢?

更新

這是一個失敗的自定義屬性。

在枚舉屬性(沒有幫助)之前,我嘗試使用entry.RefreshCache()entry.RefreshCache(new[]{"theAttributeName"}) )。

UPDATE2

entry.InvokeGet("theAttributeName")有效(並且沒有RefreshCache )。

有人可以解釋原因嗎?

UPDATE3

如果我向項目提供FQDN,它可以工作: LDAP://srv00014.ssab.com/CN=SomeName,xxxx

賞金

我正在尋找解決以下問題的答案:

  • 為什么entry.Properties["customAttributeName"]因上述異常而失敗
  • 為什么entry.InvokeGet("customAttributeName")有效
  • 異常的原因
  • 如何兼顧兩者

在這里使用Err.exe工具

http://www.microsoft.com/download/en/details.aspx?id=985

吐出來的:
對於十六進制0x8000500c /十進制-2147463156:
E_ADS_CANT_CONVERT_DATATYPE adserr.h
目錄數據類型無法轉換為/從本機轉換
DS數據類型
找到1個匹配“0x8000500c”

谷歌搜索“目錄數據類型無法轉換為/從本機”,並找到此KB: http//support.microsoft.com/kb/907462

如果想要從不屬於自定義屬性所在的域的計算機訪問自定義屬性(登錄用戶的憑據無關緊要),則需要傳遞對象的完全限定名稱訪問否則客戶端計算機上的架構緩存未正確刷新,永遠不要調用您所做的所有schema.refresh()調用

這里找到。 考慮到對問題的更新,這聽起來像是你的問題。

我有同樣的失敗。 我通過列出DirectoryEntry中的屬性閱讀並看到了很多關於錯誤0x8000500c的問題。 我可以通過Process Monitor(Sysinternals)看到我的進程已經讀取了一個模式文件。 此架構文件保存在C:\\ Users \\ xxxx \\ AppData \\ Local \\ Microsoft \\ Windows \\ SchCache \\ xyz.sch下。

刪除此文件,該程序工作正常:)

我剛剛遇到了這個問題,我的是一個Web應用程序。 我有一些代碼,它將用戶從IIS中的Windows身份驗證中拉出來並從AD中提取信息。

using (var context = new PrincipalContext(ContextType.Domain))
{
    var name = UserPrincipal.Current.DisplayName;
    var principal = UserPrincipal.FindByIdentity(context, this.user.Identity.Name);
    if (principal != null)
    {
        this.fullName = principal.GivenName + " " + principal.Surname;
    }
    else
    {
        this.fullName = string.Empty;
    }
}

這在我的測試中運行良好,但是當我發布網站時,會在FindByIdentity調用中遇到此錯誤。

我通過使用正確的用戶來修復網站的應用程序池。 一旦我解決了這個問題,這就開始了。

我對奇怪數據類型的自定義屬性有同樣的問題。 我有一個實用程序可以提取值,但是服務中的一些結構化代碼卻沒有。

該實用程序直接使用SearchResult對象,而該服務使用的是DirectoryEntry。

它提煉出來了。

SearchResult result;

result.Properties[customProp];     // might work for you
result.Properties[customProp][0];  // works for me. see below

using (DirectoryEntry entry = result.GetDirectoryEntry())
{
    entry.Properties[customProp]; // fails
    entry.InvokeGet(customProp);  // fails as well for the weird data
}

我的直覺是,SearchResult不再是一個執行者,而是返回它所擁有的任何東西。

當它轉換為DirectoryEntry時,此代碼會彈出奇怪的數據類型,以便甚至InvokeGet失敗。

我使用extra [0]的實際提取代碼如下所示:

byte[] bytes = (byte[])((result.Properties[customProp][0]));
String customValue = System.Text.Encoding.UTF8.GetString(bytes);

我從網站上的另一個帖子中獲取了第二行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM