I am getting this error while trying to retrieve a user profile:
An error was encountered while retrieving the user profile.
here is my code:
foreach (SPUser parent in parentGroup.Users)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite elevatedSite = new SPSite(site.ID))
{
using (SPWeb elevatedWeb = site.OpenWeb(web.ID))
{
elevatedWeb.EnsureUser(parent.LoginName);
}
}
});
web.EnsureUser(parent.LoginName);
try
{
UserProfile profile = upm.GetUserProfile(parent.LoginName);
if ((bool)profile["ParentAssignmentSubscribe"].Value)
{
receivingParents.Add(new SlkUser(parent));
}
}
catch(Exception ex)
{
throw new Exception("failed to load profile of " + parent.LoginName + " in order to send them an assignment notification for web " + web.Name + ". The error returned was: " + ex.Message);
}
}
obviously the user does exist, because i am getting his username from the group, and i also am using EnsureUser. what is going on?
Maybe it is because your process cannt found your user profile .
Can you try the below steps ?
Open Central Administrator-→Security-→General Security,copy user name from Configure service accounts
Open Central Administrator-→Application Management →Service Application→Manage Service Applications.
Click User Profile Service from the page you have opened at step2 , and select Manage User Profile from People
You can search the user profile by user name which you have copied at step1 , If you cant find it , that might be your error reason.
Click New Profile,create a new profile for your user name(at step1).