Wednesday, August 22, 2007

DirSync Control - SearchResult Without ObjectClass

The DirSync control is super-easy to use in .NET 2.0 with System.DirectoryServices. It is really as easy as adding one line to your regular DirectorySearcher.
DirectorySearcher searcher = new DirectorySearcher();
searcher.DirectorySynchronization = new DirectorySynchronization();

Once your query is done you can get the cookie quite easily:
Byte[] cookie = searcher.DirectorySynchronization.GetDirectorySynchronizationCookie();

I was happily using this in an XMA when I ran into what I suspect is a bug. ILM requires the objectClass when you import deleted objects. The dirSync control dutifully shows me the objectGuid (my MA's anchor attribute) then I ask it for the objectClass attribute. The attribute is there on the tombstone, I can see it using LDP. The attribute is in the DirectorySearcher's PropertiesToLoad collection, but sometimes when I ask for the objectClass it just isn't there.

Turns out this repros consistently. If the first SearchResult returned by the DirSync search is a delete then the objectClass attribute will not be present in the SearchResult.Properties collection. It will be there for the remaining SearchResult objects, but not the first.

The workaround for my MA was to put the DN back together using the 'name' and 'lastKnownParent' attributes on the tombstone, then find the objectClass using a WMI search of the ILM CS. Bugger, but the workaround works.

1 comment:

Anonymous said...

I have the same problem using an initial DirSync search [e.g. NULL cookie] against a Win2K8 DC in Win2K8 native mode. This being done using the ADSI IDirectorySearch COM interface in a native C++ application. The symptom is that although I've requested the "objectClass" attribute to be returned in my search filter & attribute list, for a consistently repeatable list of objects, the objectClass attribute is not present in the result set. In these rows, GetColumn() fails and returns an HRESULT value of 0x80005010, indicating that the column is not present.

Did you ever get a solution to this problem?

If so, please let me know - ping me at chuckchopp@rtfmcsi.com and let me know.