在Active Directory中创建用户:连接到系统的设备无法运行

请考虑此代码尝试创建Active Directory帐户。 它在这里使用一组特定数据生成exception。 目前尚不清楚导致exception的原因。

var user = new UserPrincipal(someValidUserContext, ".x-xyz-t-FooFooBarTest", "somePwd", true); user.UserPrincipalName = ".x-xyz-t-FooFooBarTest@foobarbatbaz.net"; user.SamAccountName = ".x-xyz-t-FooFooBarTest"; user.DisplayName = "Some String 16 chars long"; user.Name = "Some String 16 chars long"; user.Description = "Foo BarBaz 12 more characters"; user.AccountExpirationDate = someDateInFuture; user.UserCannotChangePassword = true; user.Save(); // exception thrown on Save(): // A device attached to the system is not functioning 

替代文字

用户代码未处理PrincipalOperationException:连接到系统的设备无法运行

造成这种exception的原因是什么,你如何解决这个问题?

sAMAccountName属性必须少于20个字符。