Hola, estuve batallando un poco con este error al momento de tratar de traerme los datos de un usuario del UserProfileManager.
Este es el codigo que tenia ese detalle:
string employeeId = default(string);
UserProfileManager profileManager = new UserProfileManager(ServerContext.GetContext(workflowActivationProperties.Site));
foreach (UserProfile userProfile in profileManager)
{
if (userProfile["employeeID"].Value != null)
{
employeeId = userProfile["employeeID"].Value.ToString().TrimStart('0');
employeeId = employeeId.Trim();
if (employeeId == idUsuario)
{
usuario.Name = userProfile["firtsName"].Value.ToString().ToUpper() + " " + userProfile["lastName"].Value.ToString().ToUpper();
usuario.AccountName = userProfile["AccountName"].Value.ToString();
usuario.WorkEmail = userProfile["WorkEmail"].Value.ToString();
usuario.EmplyeeID = idUsuario;
usuario.JobTitle = GetDescripcion("C", idUsuario);
break;
}
}
}
Solución:
Agregar permisos elevados antes de ejectuar la acción requerida.
string employeeId = default(string);
SPSecurity.RunWithElevatedPrivileges(delegate()
{
UserProfileManager profileManager = new UserProfileManager(ServerContext.GetContext(workflowActivationProperties.Site));
foreach (UserProfile userProfile in profileManager)
{
if (userProfile["employeeID"].Value != null)
{
employeeId = userProfile["employeeID"].Value.ToString().TrimStart('0');
employeeId = employeeId.Trim();
if (employeeId == idUsuario)
{
usuario.Name = userProfile["firtsName"].Value.ToString().ToUpper() + " " + userProfile["lastName"].Value.ToString().ToUpper();
usuario.AccountName = userProfile["AccountName"].Value.ToString();
usuario.WorkEmail = userProfile["WorkEmail"].Value.ToString();
usuario.EmplyeeID = idUsuario;
usuario.JobTitle = GetDescripcion("C", idUsuario);
break;
}
}
}
});