How to resolve "No User Profile Application available to service the request"


When I was trying to get the user properties

ServerContext
serverContext = ServerContext.GetContext(site);
UserProfileManager upm = new UserProfileManager(serverContext);
UserProfile up = upm.GetUserProfile(strAccountName);

I was getting the following error. 

nouserprofile1.gif  

How to resolve:
  • Go to Central Administration => Application Management => Manage Service Applications => User Profile Service Application

    nouserprofile2.gif

  • Click on Administrators => Add the user and give Full Control.

  • Click on Permissions => Add the user and give Full Control.