PROBLEM STATEMENT In writing some provisioning code in a metaverse extension, I came across a problem while attempting to create the DN for an Active Directory Lightweight Directory Services (AD LDS) Management Agent. Debugging the code, I was able to see that I am getting an "DN <name of DN> is not valid" ERROR MESSAGE Microsoft.MetadirectoryServices.InvalidDNException was caught Message=DN "CN=LastName, FirstName,ou=users,dc=devdomain,dc=local" is not valid. Source=mmsscpth MAName=ADLDS StackTrace: at Microsoft.MetadirectoryServices.Impl.ScriptHost.TransformDNToStoreForm(ManagementAgent pMA, String pstrDN) at Microsoft.MetadirectoryServices.Impl.ManagementAgentImpl.CreateDN(String dn) at Microsoft.MetadirectoryServices.Impl.ConnectedMAImpl.CreateDN(String dn) at Mms_Metaverse.MVExtensionObject.Microsoft.MetadirectoryServices.IMVSynchronization.Provision(MVEntry mventry) in C:\Provisioning Code\MVExtension\MVExtension.cs:line 89 InnerException:
GOAL / Here is what I want the DN to look like CN=LastName, FirstName, OU=Users, DC=devdomain, DC=local CODE string rdn = "CN=" + mventry["CN"].Value.ToString(); string container = "ou=users,dc=dev,dc=local"; dn = ManagementAgent.CreateDN(rdn + "," + container); RESOLUTION We had to escape the "," that was in the CN. In Visual C#, you will need to escape the escape character. You can do this in one of two ways. rdn = rdn.Replace(",", "\\,") or rdn = rdn.Replace(",", @"\,") Once we updated the code, and then re-compiled, the error message went away. SEE ALSO
Richard Mueller edited Revision 3. Comment: Added comma to the Relace method to separate the old and new string values (in Resolution section)
Richard Mueller edited Revision 2. Comment: Added link to Wiki documenting all characters that must be escaped in Active Directory