The code you have should be fine - it works for me, no problem.
However: you do not tell us what you fill out for domain_namehere:
PrincipalContext domainContext = new PrincipalContext(ContextType.Domain, "domain_name");
userId :
UserPrincipal p = UserPrincipal.FindByIdentity(domainContext, IdentityType.SamAccountName, UserId);
domain_name "" NetBIOS, . FABRIKAM - DNS, fabrikam.com AD-style, dc=fabrikom,dc=com LDAP.
userId SAM, . . 20 , ( ).
?