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

p.c*_*ell 34 c# active-directory asp.net-3.5

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

 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
Run Code Online (Sandbox Code Playgroud)

替代文字

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

导致此异常的原因是什么,您如何解决这个问题?

Ger*_*erm 68

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

  • 微软可能会显示的另一条消息:您刚刚遇到错误.敬上.微软. (22认同)
  • 6年下线和相同的血腥错误信息.我是在想"肯定谷歌没有用这样的通用错误信息".是的,20个字符仍然是限制和问题解决者! (3认同)
  • 这是一篇非常有诗意的文章,我刚刚发现了这个问题:http://usrlocal.com/2009/08/a-device-attached-to-the-system-is-not-functioning/再次......一点点讽刺:) (2认同)