C# Error when adding Member to UserGroup

Version 1
    This document was generated from CDN thread

    Created by: Chris Bertrand on 16-03-2010 02:25:27 PM
    I am trying to add a exisiting user into a user group.
     
    When calling the updateUserGroup method i get the error "There was an error generating the XML document" it then states
     
    InnerException = {"Value of ItemsElementName mismatches the type of UpdateUserGroupReqAddMembers; you need to set it to ItemsChoiceType6.@addMembers."}
     
    Here is the code i used, i am setting the element name to add members so am confused as to why this is occuring. Using v7
     
    UpdateUserGroupReq userGroup = new UpdateUserGroupReq();
    userGroup.ItemElementName = ItemChoiceType62.name;
    userGroup.Item = Group;
     
    UpdateUserGroupReqAddMembers reqMems = new UpdateUserGroupReqAddMembers();
    userGroup.ItemsElementName =new ItemsChoiceType6[1];
    userGroup.ItemsElementName[0] = ItemsChoiceType6.addMembers; 
    XUserGroupMember mem = new XUserGroupMember();
    mem.Item = UserID;
    XUserGroupMember[] mems = new XUserGroupMember[1];

    mems.SetValue(mem, 0);
    reqMems.member = mems;
    userGroup.Items = reqMems.member;

    axlService.updateUserGroup(userGroup);
     
    Any ideas?

     

    Subject: RE: C# Error when adding Member to UserGroup
    Replied by: Chris Bertrand on 17-03-2010 10:24:00 AM
    Heres a nice function i made that does this.
     
     
     
     
     
     
     
     
     
     
     
     
     

     
    public void addUserToGroup(String UserID, String Group)
    {
     
    //Do a quick check to see if they exist
     
    GetUserGroupRes res = new GetUserGroupRes();
     
    //Add
     
    UpdateUserGroupReq userGroup = new UpdateUserGroupReq();
    userGroup.ItemElementName = ItemChoiceType62.name;
    userGroup.Item = Group;
     
    UpdateUserGroupReqAddMembers reqMems = new UpdateUserGroupReqAddMembers();
    userGroup.ItemsElementName = new ItemsChoiceType6[4];
    userGroup.ItemsElementName[0] = ItemsChoiceType6.addMembers;
     
    XUserGroupMember mem = new XUserGroupMember();
    mem.Item = UserID;
     
    XUserGroupMember[] mems = new XUserGroupMember[4];
    mems.SetValue(mem, 0);
    reqMems.member = mems;
    userGroup.Items = new UpdateUserGroupReqAddMembers[4];

    userGroup.Items[0] = reqMems;
    axlService.updateUserGroup(userGroup);
    }
    <font size="2">
     
    </font>