1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / Error when calling SetValue() on UserProfile Object

Error when calling SetValue() on UserProfile Object

2 posts, 0 answered
  1. Shane
    Shane avatar
    5 posts
    Registered:
    14 Apr 2011
    30 Sep 2011
    Link to this post
    I am attempting to create a user in code and am encountering some issues. I use the UserManager to create the user (UserManager.CreateUser) then I call CreateProfile on the UserProfileManager.  All of this works fine.  However I have a number of custom fields on the user profile that I need to set.  I've created all of the fields using the Manage Profile Types in the backend but when I attempt to set the value of the property in code by calling UserProfile.SetValue() I get the following error:  Sequence contains more than one matching element.  This happens for every field I attempt to set.  I also get the same error message if I call GetValue().

    Here is the code:

    --Code to create user
    public bool CreateWebUser(string userName, string firstName, string lastName, string title, string organization, string organizationUrl, string address1, string address2,
                               string city, string state, string zip, string country, string socialProfileType, string socialProfile, string email, string officePhone,
                               string mobilePhone, string role, string password, string publications, string links, string securityQuestion, string securityAnswer)
            {
                bool returnValue = false;
                if (this._userManagerProvider.GetUser(userName) == null)
                {
     
                    User persistedUser = this._userManagerProvider.CreateUser(userName); 
                    persistedUser.Email = email;
                    persistedUser.Password = password;
                    persistedUser.SetPasswordQuestion(securityQuestion);
                    persistedUser.PasswordAnswer = securityAnswer;
                     
                    WebUserProfile webUserProfile = this._webUserProfileManager.CreateProfile(persistedUser, CCG_USER_PROFILE_NAME);
                    webUserProfile.FirstName = firstName;
                    webUserProfile.LastName = lastName;
                    webUserProfile.Title = title;
                    webUserProfile.Organization = organization;
                    webUserProfile.OrganizationURL = organizationUrl;
                    webUserProfile.Address1 = address1;
                    webUserProfile.Address2 = address2;
                    webUserProfile.City = city;
                    webUserProfile.State = state;
                    webUserProfile.ZipCode = zip;
                    webUserProfile.Country = country;
                    webUserProfile.SocialMediaProfileType = socialProfileType;
                    webUserProfile.SocialMediaProfile = socialProfile;
                    webUserProfile.OfficePhone = officePhone;
                    webUserProfile.MobilePhone = mobilePhone;
                    webUserProfile.Publications = publications;
                    webUserProfile.LinksToWork = links;
     
                    this._webUserProfileManager.SetProfileValues(webUserProfile);
                    if(!string.IsNullOrEmpty(role))
                        this._roleManagerProvider.AddUserToRole(persistedUser, role);
     
                    SaveChanges();
     
                    //SendConfirmationEmail(firstName, email, persistedUser.Id.ToString());
     
                    returnValue = true;
                }
     
                return returnValue;
            }

    --Code to set profile values.  This is the method that is causing the exception:
    public bool SetProfileValues(WebUserProfile webUserProfile)
            {
                webUserProfile.UserProfile.SetValue(PROFILEFIELD_FIRSTNAME, webUserProfile.FirstName);
                webUserProfile.UserProfile.SetValue(PROFILEFIELD_LASTNAME, webUserProfile.LastName);
                webUserProfile.UserProfile.SetValue(PROFILEFIELD_MIDDLEINIT, webUserProfile.MiddleInitial);
                webUserProfile.UserProfile.SetValue(PROFILEFIELD_TITLE, webUserProfile.Title);
                webUserProfile.UserProfile.SetValue(PROFILEFIELD_ORGANIZATION, webUserProfile.Organization);
                webUserProfile.UserProfile.SetValue(PROFILEFIELD_ORGANIZATIONURL, webUserProfile.OrganizationURL);
                webUserProfile.UserProfile.SetValue(PROFILEFIELD_SOCIALPROFILETYPE, webUserProfile.SocialMediaProfileType);
                webUserProfile.UserProfile.SetValue(PROFILEFIELD_SOCIALPROFILE, webUserProfile.SocialMediaProfile);
                webUserProfile.UserProfile.SetValue(PROFILEFIELD_ADDRESS1, webUserProfile.Address1);
                webUserProfile.UserProfile.SetValue(PROFILEFIELD_ADDRESS2, webUserProfile.Address2);
                webUserProfile.UserProfile.SetValue(PROFILEFIELD_CITY, webUserProfile.City);
                webUserProfile.UserProfile.SetValue(PROFILEFIELD_STATE, webUserProfile.State);
                webUserProfile.UserProfile.SetValue(PROFILEFIELD_ZIPCODE, webUserProfile.ZipCode);
                webUserProfile.UserProfile.SetValue(PROFILEFIELD_COUNTRY, webUserProfile.Country);
                webUserProfile.UserProfile.SetValue(PROFILEFIELD_OFFICEPHONE, webUserProfile.OfficePhone);
                webUserProfile.UserProfile.SetValue(PROFILEFIELD_MOBILEPHONE, webUserProfile.MobilePhone);
                webUserProfile.UserProfile.SetValue(PROFILEFIELD_PUBLICATIONS, webUserProfile.Publications);
                webUserProfile.UserProfile.SetValue(PROFILEFIELD_LINKSTOWORK, webUserProfile.LinksToWork);
                webUserProfile.UserProfile.SetValue(PROFILEFIELD_SELECTEDPROFILE, webUserProfile.SelectedProfile);
                webUserProfile.UserProfile.SetValue(PROFILEFIELD_STATUS, webUserProfile.RegistrationStatus.ToString());
                return true;
            }

    Any ideas on how to resolve this?

    Thanks
    Shane
  2. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    04 Oct 2011
    Link to this post
    Hello Shane,

    The ticket has been answered as a support ticket. The problem was coming from a property named Title that is created again in the model and the query couldn't recognise which one to select.

    Best wishes,
    Svetoslav Petsov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered