Today I have come across beautiful error exception
I would like to share How to fix it
My code is as follows:
using (var context = new PrincipalContext(ContextType.Domain, domainName, systemUserName, systemPwd))
UserPrincipal up = new UserPrincipal(context);
up.SamAccountName = samAccountName;
catch (Exception exception)
This is by itself pretty straight forward code
Turns out that the data I have been passing in have been greater than 20 characters for SamAccountName.
The field SamAccounName has limit 20 characters.