TROUBLESHOOTING: DN is not valid

TROUBLESHOOTING: DN is not valid

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

 

Leave a Comment
  • Please add 4 and 3 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • 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

Page 1 of 1 (2 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Richard Mueller edited Revision 2. Comment: Added link to Wiki documenting all characters that must be escaped in Active Directory

  • Richard Mueller edited Revision 3. Comment: Added comma to the Relace method to separate the old and new string values (in Resolution section)

Page 1 of 1 (2 items)