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 accessing the User Profile Property in my console application to view the current logged in user's department, where "Department" is the property of user profile.

To access the property I referred this post. My code is:

class Program
    static void Main(string[] args)
        using (SPSite siteCollection = new SPSite("http://.............."))
            using (SPWeb site = siteCollection.OpenWeb())
                SPUser spUser = site.CurrentUser;
                ServerContext serverContext = ServerContext.GetContext(siteCollection);
                UserProfileManager userProfileManager = new UserProfileManager(serverContext);

                UserProfile profile = userProfileManager.GetUserProfile(spUser.LoginName);
                Console.WriteLine("Current Logged In User Department:" + profile["Department"]);

I am getting the error at line: UserProfileManager userProfileManager = new UserProfileManager(serverContext); that "UserProfileApplicationNotAvailableException was unhandled".

What am I missing ?

share|improve this question
if all you need is the current user, you can pass an emptystring rather than spUser.LoginName. As for the error, you probably don't have permission on the UPA, check Karthik's response – Matthew McDermott Sep 30 '13 at 21:52

Few days back, I was getting "No User Profile Application available to service the request. Contact your farm administrator" error, I made sure that the User Profile Application was running correctly and it was. I already clicked on the “Administrators” button in the toolbar of the Service Application to give me Full Control, but it still wasn’t working.

Then I noticed that there is also a ‘Permissions’ button for the created user profile service in the "Manager Service Application" page. I clicked the button and saw that my current user wasn’t in the permissions box. I gave my user ‘Full Control’ and now everything works great from the console application.

Hope this helps you.

share|improve this answer
If the above answer was useful and correct, please mark it as answer, so that it will be helpful to others too. – Karthik Jaganathan Oct 4 '13 at 18:35
as @Karthik said you need full control:… – Nk SP Jan 15 '15 at 18:50
This. I am in the habit of running all UserProfile administrative operations under the farm admin credentials; however, as this response describes, any account can be used so long as they have permissions on the UPS. – kbrimington Jan 15 '15 at 22:11

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.