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"
Microsoft.MetadirectoryServices.InvalidDNException was caught
Message=DN "CN=LastName, FirstName,ou=users,dc=devdomain,dc=local" is not valid.
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
GOAL / Here is what I want the DN to look like
CN=LastName, FirstName, OU=Users, DC=devdomain, DC=local
string rdn = "CN=" + mventry["CN"].Value.ToString();
string container = "ou=users,dc=dev,dc=local";
dn = ManagementAgent.CreateDN(rdn + "," + container);
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.