From the ministry of silly error messages …
When creating a user through Active Directory you receive the error “A first chance exception of type 'System.DirectoryServices.DirectoryServicesCOMException' occurred in System.DirectoryServices.dll: A device attached to the system is not functioning.
“.
Chances are the sAMAccountName property was set to a string of 20 characters or more.
After hours of playing with my code, this solution solved my error. I was setting a samaccountname of more then 20 letters. You have NO idea how much I appreciate finding this site. 🙂
Saved me a nightmare! Thank you