1

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!

6
  • Does the profile of user exists?
    – Amit
    May 15, 2015 at 11:34
  • @Amit yes is does
    – IDeveloper
    May 15, 2015 at 11:43
  • Is it running under an account that has permission to modify the user's profile? May 15, 2015 at 13:50
  • @EricAlexander yes it runs under farm admin account
    – IDeveloper
    May 17, 2015 at 4:05
  • Is it an Open or Closed Term Set? May 17, 2015 at 11:45

1 Answer 1

0

replace prop.clear() with prop.Value=null;

if (userDepGuid != Guid.Empty)
    {
        //prop.Clear();
       prop.Value=null;
        var newValue = ts.GetTerm(userDepGuid);
        prop.AddTaxonomyTerm(newValue);
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.