Getting an “Object reference not set to an instance of an object” when accessing the User Profile Service via Code

This is one of the posts which shall remind me about something. And may help others as well.

Coding against the User “Profile Service Application requires Connection Permissions for the executing user account!

From the beginning. I wrote a console application which leverages the User Profile Store. Every time I created a new instance of the UserProfileConfigManager class, an exception was thrown:

Object reference not set to an instance of an object

at Microsoft.Office.Server.Administration.UserProfileApplicationProxy.get_ApplicationProperties()
at Microsoft.Office.Server.Administration.UserProfileApplicationProxy.get_ILMMachineName()
at Microsoft.Office.Server.UserProfiles.UserProfileConfigManager.Initialize(UserProfileApplicationProxy userProfileApplicationProxy, Guid partitionID)
at Microsoft.Office.Server.UserProfiles.UserProfileConfigManager..ctor(SPServiceContext serviceContext)
at ITaCS.UserProfileManager.GetUserProfileServer() in D:\Data\Development\tfs02\ITaCS\Components\UserProfileProperties\UserProfileProperties\UserProfileManager.cs:line 49
asf

Fiddling with Reflector and creating the object with Reflection didn’t help. The solution was much easier. Just grant the executing account, which was my user who executes the console application, Connection Permissions to the User Profile Store Service Application (UPS).

image

image

That’s it.

One other thing. If you are running your SharePoint with local accounts, you might not be able to verify a domain account. In that case, you can tell the people picker to use a domain account instead of the service account (which is a local account and does not have permissions in the active directory). See Configure People Picker (SharePoint Server 2010) and  Multi Forest/Cross Forest People Picker peoplepicker-searchadcustomquery.