更新某些字段不起作用,而其他字段则不起作用。即使旧值和新值是字符串,也会抛出异常。
UserPrincipal user = GetUser();
var userEntry = user.GetUnderlyingObject() as DirectoryEntry;
// When creating user this kind of stuff works
userEntry.Properties["pager"].Add("12345");
user.Save();
// When updating this doesn't work for attributes
// E.g. mobile has value "+12 34 567 89 01" of type String
userEntry.Properties["mobile"].Value = "0345678901"; // not ok
user.Save();
// Exception 'The attribute syntax specified to the directory service is invalid.'
// also not ok
userEntry.Properties["mobile"].RemoveAt(0);
userEntry.Properties["mobile"].Add("0345678901");
user.Save();