SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a strange issue where when I call EnsureUser I get an error that the SharePoint user is not unique or cannot be found.

I have set up claims auth in 2010 using SQL membership provider. Got all the correct membership and profile entries in main site, CA and Security token web.configs.

I have the membership accounts created such that the email address is used for the username field as well as the email field.

The crazy thing is that for certain email addresses EnsureUser works fine but for others I get the error. I just can't work out why that would be.

Even if the code errors I am able to use the UI and manually add the FBA user using people picker with no error just fine.

The code which attempts to run EnsureUser is running in an elevated priv with correctly instantiated new SPSite and SPWeb objects and AllowUnSafeupdates set to true.

Any ideas?

share|improve this question
up vote 6 down vote accepted

Try to prefix the username with the membership provider info. It would look something like:

share|improve this answer
Ahaa! I was actually doing that previously but removed it as I thought it was causing other issues. I used the following function in the end. public static string EncodeUsername(string username) { SPClaim claim = new SPClaim(SPClaimTypes.UserLogonName, username, "", SPOriginalIssuers.Format(SPOriginalIssuerType.Forms, GetMembershipProvider())); return SPClaimProviderManager.Local.EncodeClaim(claim); } – PlanetWilson Sep 29 '12 at 7:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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