In writing some provisioning code in a metaverse extension, you can come across a problem while attempting to create the DN for an Active Directory Lightweight Directory Services (AD LDS) Management Agent.
Debugging the code shows a "DN <name of DN> is not valid" 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:
Here is what we 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.
Once we updated the code and then re-compiled, the error message went away.