Skip to content

DirectoryEntry RefreshCache for property subset not clearing uncommitted changes #87197

Open
@hellblade

Description

@hellblade

Description

The DirectoryEntry.RefreshCache method has an overload to take in just a limited number of properties to refresh.
See Documentation

This does not seem to refresh the cache for a property when:

  • The object in Acitve Directory does not have any existing values for the property
  • You have added a value to the property collection cache

It works correctly if the object does have an existing value for the property, or of course with the non-overloaded RefreshCache method.

Reproduction Steps

You will need an Active Directory server, and the object guid for an object with no publicDelegates set. Note it's not limited to publicDelegates so could use another too.

var directoryEntry = new DirectoryEntry($"LDAP://{server}/<GUID={objectGuid}>", username, password, AuthenticationTypes.Sealing | AuthenticationTypes.Secure | AuthenticationTypes.Signing);
           
directoryEntry.RefreshCache(new string[] { "publicDelegates" });

var delegates = directoryEntry.Properties["publicDelegates"];
		  
// If this GUID is invalid then commit changes throws an error. If it is valid then it gets added
delegates.Add("<GUID=8d80e043-4aaf-4439-9549-acea08998e74>");
directoryEntry.RefreshCache(new string[] { "publicDelegates" });

directoryEntry.CommitChanges();

Using the non-overloaded RefreshCache works correctly and the object has no changes made to it (and no exception if the GUID is invalid):

var directoryEntry = new DirectoryEntry($"LDAP://{server}/<GUID={objectGuid}>", username, password, AuthenticationTypes.Sealing | AuthenticationTypes.Secure | AuthenticationTypes.Signing);
           
directoryEntry.RefreshCache(new string[] { "publicDelegates" });

var delegates = directoryEntry.Properties["publicDelegates"];
		  
delegates.Add("<GUID=8d80e043-4aaf-4439-9549-acea08998e74>");
directoryEntry.RefreshCache();

directoryEntry.CommitChanges();

Expected behavior

Calling RefreshCache(String[]) should clear the cache for all properties provided, even if the object bound to has no values for the property.

Actual behavior

Calling RefreshCache(String[]) does not clear the cache properties provided where the object bound has no existing values.

Regression?

No response

Known Workarounds

Use the RefreshCache() overload which may mean more data than required is read in.

Configuration

.NET6
Windows 11
x64

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions