UserProfileManager object creating fails when we try to create an instance from a SharePoint workflow application.

A work-around to this issue is, execute the code under admin privileges(impersonate the user), you can either follow the Win API impersonation or using the SPSecurity.RunWithElevatedPrivilages() method.

You would get errors like,

'Microsoft.SharePoint.SPException'

base {System.ApplicationException}: {"Cannot complete this action.\n\nPlease try again."}

ErrorCode: -2147467259

UserProfileChangeJobSchedule: 'new UserProfileManager(context,false).UserProfileChangeJobSchedule' threw an exception of type 'Microsoft.SharePoint.SPException'

SPSecurity.RunWithElevatedPrivilages(delegate()

{

ServerContext context = ServerContext.GetContext("SharedServices2");

UserProfileManager manager = new UserProfileManager(context);

});