You must change the filter to look like this:
var filter = string.Format("(&(objectCategory={0})(objectClass={1})(sAMAccountName={2}))", "person", "user", username);
However, this will not work in any LDAP directory. sAMAccountName , for example, is an AD-specific attribute.
source share