I read statements like this several times on various blogs and in technical articles:
“Limited Access is a special permission level that cannot be assigned to a user or group directly.” (source)
However, this is only the half of the truth.
Assume, you have a role assignment (SPRoleAssignment) that contains a reference to the Limited Access role definition (SPRoleDefinition):
web.RoleDefinitions.GetByType(SPRoleType.Guest); // “Users cannot be added explicitly to the Guest role” again… (source)
It’s true, that when you use the “standard” overload of the Add method of the SPRoleAssignmentCollection, SPRoleAssignmentCollection.Add(SPRoleAssignment) with this role assignment, you get an exception like this:
You cannot grant a user the limited access permission level.
But if you use the other overload, SPRoleAssignmentCollection.Add(SPPrincipal), it does just that, grants the principal the Limited Access permissions.
grants the group the Limited Access permission on the web site.