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 am Updating the the status message on user profile to some default value through the code. but now i am getting " Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. "

i am using the below code to do the same

string socialDataStatsSite = "mysiteurl";

            SPSite siteColl = new SPSite(socialDataStatsSite);

                SPWeb st = siteColl.OpenWeb();

              //  SPServiceContext serviceContext = SPServiceContext.GetContext(siteColl);
                    HttpContext.Current = null; 
                    ServerContext serviceContext = ServerContext.GetContext(siteColl);
                UserProfileManager manger = new UserProfileManager(serviceContext);

                //  UserProfile userProfile = ProfileLoader.GetProfileLoader().GetUserProfile();
                UserProfile userProfile = manger.GetUserProfile(id);
               // SPContext.Current.Web.AllowUnsafeUpdates = true;
                siteColl.AllowUnsafeUpdates = true;

                userProfile["SPS-StatusNotes"].Value = "default";



share|improve this question

Your code should look more like this, but the id, is that the username? UserExists(string AccountName) is the reason I am asking. Anyway here is more like what the code should look like. There are a couple of things wrong with your code, so it's hard to tell what exactly is throwing the exception.

        using (SPSite oSite = new SPSite(socialDataStatsSite))
           SPServiceContext oContext = SPServiceContext.GetContext(oSite);
           UserProfileManager oProfileManager = new UserProfileManager(oContext);

           if (oProfileManager.UserExists(id))
               UserProfile oProfile = oProfileManager.GetUserProfile(id);
               oProfile[PropertyConstants.StatusNotes].Value = "default";
share|improve this answer

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.