I m trying to update the user profile "State" custom property using below code but getting following error.

We have even tried to restart the user profile service but it couldn't fix the issue.

Any help is highly appreciated.

 public static void UpdateUserProfile(SPSite site, string sAccount, string State)
                SPSecurity.RunWithElevatedPrivileges(delegate ()
                    using (SPSite _site = new SPSite(site.ID))
                        var serviceContext = SPServiceContext.GetContext(site);
                        var profileManager = new UserProfileManager(serviceContext);
                        if (!profileManager.UserExists(sAccount)) profileManager.CreateUserProfile(sAccount);
                        var userProfile = profileManager.GetUserProfile(sAccount);
                        userProfile["State"].Value = State;
            catch (Exception ex)
                Logger.Error(string.Format("ERROR {0} : {1}.", System.Reflection.MethodBase.GetCurrentMethod().Name, ex.Message));

An exception of type 'Microsoft.Office.Server.UserProfiles.UserProfileApplicationNotAvailableException' occurred in Microsoft.Office.Server.UserProfiles.dll but was not handled in user code

Additional information: UserProfileDBCache_WCFLogging :: ProfileDBCacheServiceClient.GetUserData threw exception: Access is denied.


1 Answer 1


You should firstly check the permission your code running for retrieve User Profile information.

SPSecurity.RunWithElevatedPrivileges Method is used for running the code block under the Application Pool identity, which has site collection administrator privileges on all site collections hosted by that application pool.

In your code snippet, UserProfileManager object is used, so please authorize permission(in ServiceApplications-->User Profile Service Application) to this site collection administrator.

  • Thanks hardik, authorizing permission resolved the issue.
    – savita
    Dec 19, 2018 at 9:17
  • If this answer helped you then you can mark it as correct so others will trust this answer easily & get benefit from it. Thanks :)
    – Hardik
    Dec 19, 2018 at 9:18

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.