could you please help me understand why my code isn't work properly:
_domainService = new DomainServices(AdUserName, AdUserPass,AdUserDN);
using UserPrincipal user = UserPrincipal.FindByIdentity(_domainService.CurrentGlobalContext, IdentityType.SamAccountName, "MyUserName");
DirectoryEntry? directoryEntry = user.GetUnderlyingObject() as DirectoryEntry;
var propList = adUser.BuildPropertiesList().ToArray<string>();
directoryEntry!.RefreshCache(propList);
The code above returns me always 35 properties, whereas my list of properties uploaded to the RefreshCache method is only 27 and besides that thouse 35 doesn't have thouse I was identified ib my propList variable. I checked tons of posts here and tried dozens of solutions but it seems it is just simply ignored whatever i put in RefreshCache method. even if UsePropertyCache is true it is not working as i need. I did even tried to pull only one prop directoryEntry.RefreshCache(new string[] { "mobile" }); but as a result I get 35 properties and non of them was "mobile" ...
Appreciate your help in advance, Best regards, Maks.
Well, as i find out, this wasn't a problem at all.
RefreshCache will return you only thouse properties which has been initialized with value.
If you would like to discover all possible properties that exists in directory entry use following snippet:
Note code snippet has been borrowed from How to get ALL available properties for a DirectoryEntry. I did refactor it a bit as proposed solution isn't working in VS 2022, unfortunatelly I wasn't able to place my comment in original subject as my repuitation < 50
That's all, Hope this will be helpfull for you and could save some time.