Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveDirectory error 0x8000500c when traversing properties

I got the following snippet (SomeName/SomeDomain contains real values in my code)

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

It prints OK for the first 21 properties, but then fail with:

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

Why? How can I prevent it?

Update

It's a custom attribute that fails.

I've tried to use entry.RefreshCache() and entry.RefreshCache(new[]{"theAttributeName"}) before enumerating the properties (which didn't help).

Update2

entry.InvokeGet("theAttributeName") works (and without RefreshCache).

Can someone explain why?

Update3

It works if I supply the FQDN to the item: LDAP://srv00014.ssab.com/CN=SomeName,xxxx

Bounty

I'm looking for an answer which addresses the following:

  • Why entry.Properties["customAttributeName"] fails with the mentioned exception
  • Why entry.InvokeGet("customAttributeName") works
  • The cause of the exception
  • How to get both working
like image 751
jgauffin Avatar asked Mar 16 '12 12:03

jgauffin


3 Answers

If one wants to access a custom attribute from a machine that is not part of the domain where the custom attribute resides (the credentials of the logged in user don't matter) one needs to pass the fully qualified name of the object is trying to access otherwise the schema cache on the client machine is not properly refreshed, nevermind all the schema.refresh() calls you make

Found here. This sounds like your problem, given the updates made to the question.

like image 111
Chris Gessler Avatar answered Nov 11 '22 10:11

Chris Gessler


Using the Err.exe tool here

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

It spits out:
for hex 0x8000500c / decimal -2147463156 :
E_ADS_CANT_CONVERT_DATATYPE adserr.h
The directory datatype cannot be converted to/from a native
DS datatype
1 matches found for "0x8000500c"

Googled "The directory datatype cannot be converted to/from a native" and found this KB: http://support.microsoft.com/kb/907462

like image 20
Jeremy Thompson Avatar answered Nov 11 '22 09:11

Jeremy Thompson


I have the same failure. I´m read and saw a lot of questions about the error 0x8000500c by listing attribute from a DirectoryEntry. I could see, with the Process Monitor (Sysinternals), that my process has read a schema file. This schema file is saved under C:\Users\xxxx\AppData\Local\Microsoft\Windows\SchCache\xyz.sch.

Remove this file and the program works fine :)

like image 30
Nerospeed Avatar answered Nov 11 '22 10:11

Nerospeed