I've seen this question and tried with both "userPrincipalName" and "userFlags" and I'm receiving "The specified directory service attribute or value does not exist" in both cases.
I am able to set the attribute with the following in Powershell
Get-ADUser -Filter 'cn -like "*username*"' -Server <serveraddrress> -SearchBase "<searchbase>" | Set-ADUser -PasswordNeverExpires:$True
My C# code is as follows, it works fine if I remove the line setting userAccountControl, but it creates the user with Password Never Expires = FALSE
using (var dirEntry = entry.Children.Add("CN=" + username, "user"))
{
dirEntry.Properties["userPrincipalName"].Value = string.Format("{0}@principal", username);
dirEntry.CommitChanges();
dirEntry.Options.PasswordPort = port;
dirEntry.Options.PasswordEncoding = PasswordEncodingMethod.PasswordEncodingClear;
dirEntry.Invoke("SetPassword", password);
if (!string.IsNullOrEmpty(email))
dirEntry.Properties["mail"].Value = email;
dirEntry.Properties["msDS-UserAccountDisabled"].Value = "FALSE";
//this doesn't work with both "userAccountControl" and "userFlags"
dirEntry.Properties["userAccountControl"].Value = (int)(dirEntry.Properties["userAccountControl"].Value ?? 0) | 0x10000;
dirEntry.CommitChanges();
}