I have a custom webpart in which I get the SPUser object from email address, see the code below. It was working fine for like an year now , but since yesterday it gives a

"User cannot be found"

error. There was no change made in the code or anywhere else. And I checked in the User Information List whether those email addresses exists and they do. I do understand what is causing this error. Any suggestion on were to look is appreciated.

Here is the line that's causing problem now:

spUser = spWeb.SiteUsers.GetByEmail(txtEmail.Text);


I also tried checking through powershell by the following method. In this case I am getting some of the users correctly. but for some other users email addresses I tried, it returns the same

"user cannot be found" exception.

$user = $web.Users.GetByEmail("[email protected]")
  • Can you please check the User Exists in Active Directory ? User deleted is not synced with UserInformationList instantly Commented Jun 16, 2016 at 11:49
  • @AkarshGupta ... The users are both in AD and in the user info list. And both places have the email address set. Commented Jun 16, 2016 at 12:36
  • 1
    For your Powershell, to make sure you're comparing apples to apples, make sure you access $web.SiteUsers instead of $web.Users
    – Thriggle
    Commented Jun 16, 2016 at 20:20
  • @Thriggle Thanks for that tip but that doesnt solve my issue. Commented Jun 17, 2016 at 11:19

2 Answers 2


One option may be to replace spWeb.SiteUsers.GetByEmail with spWeb.EnsureUser.

Even though the documentation indicates that EnsureUser accepts a user's domain\username as a parameter, in practice I've found that an email address works as well, although this may be dependent on your environment's configuration.


kindly try below.

spUser = spWeb.AllUsers.GetByEmail(txtEmail.Text);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.