active-directorydirectoryentry

DirectoryServicesCOMException when clear AD Property (CountryCode)


I try clear COUNTRYCODE property for ActiveDirectory using NET (DirectoryEntry, PrincipalContext)

public const String COUNTRYCODE = "countryCode";


    if (dEntry.Properties.Contains(property))
    {
        dEntry.Properties[property].Clear();
        dEntry.CommitChanges();
        dEntry.Close();
        return;
    }

The error:

System.DirectoryServices.DirectoryServicesCOMException

ExtendedError 8311

ExtendedMessage: 00002077: SvcErr: DSID-031903C9, problem 5003 (WILL_NOT_PERFORM), data 0

I try:

dEntry.Invoke("Remove", new object[] { property }); 

or

dEntry.Invoke("remove", new object[] { property });

I get the error:

System.Runtime.InteropServices.COMException: Nombre desconocido. (0x80020006 (DISP_E_UNKNOWNNAME))


Solution

  • When you see WILL_NOT_PERFORM, it means you are trying to do something that is not allowed.

    You cannot clear the countryCode attribute. It must have a value. You can set it to 0 if you'd like.