I've written a timer job with C# that sets some user properties, including SPS-Department which is bound to a Term Set. Job works perfect on dev machine. On product machine it fails with exception:
Exception caught for user domain\user. Message: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index. Stack: at System.Collections.ArrayList.get_Item(Int32 index) at Microsoft.Office.Server.UserProfiles.ProfileValueCollectionBase.AddTaxonomyTerm(Term term) at ADUpdater.Code.ColvirToUserProfileUpdater.UpdateUserProfilesFromColvir(String connectionString, String webAppUrl)
My code looks like this:
...
var prop = userProfile[PropertyConstants.SPSDepartment];
UserProfileConfigManager upcManager = new UserProfileConfigManager(serviceCtx);
ProfilePropertyManager propManager = upcManager.ProfilePropertyManager;
CorePropertyManager corePropertyManager = profileManager.GetCoreProperties();
CoreProperty property = corePropertyManager.GetPropertyByName(PropertyConstants.SPSDepartment);
TermSet ts = property.TermSet;
if (userDepGuid != Guid.Empty)
{
prop.Clear();
var newValue = ts.GetTerm(userDepGuid);
prop.AddTaxonomyTerm(newValue);
}
...
userProfile.Commit();
userDepGuid
is not null, newValue
also is not null. I'm stuck. Some fresh ideas might be extremely helpful. Thank you in advance!