1

When I try to load

owner = TargetSite.Web.EnsureUser(grp.Owner.LoginName);

I got the exception :

The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested

How can I lod this properties ? .

  private static void InsertGroup()
    {
        GroupCreationInformation groupCreationInfo = new GroupCreationInformation();
        try
        {  
             foreach(string Item in Selecteditems ){
            foreach (Group grp in SourceGroups)
            {

                if (!string.IsNullOrEmpty(grp.Title) && grp.Title == Item)
                {
                    try
                    {  
                         using(var srcSite =  new ClientContext(grp.Context.Url)){
                        groupCreationInfo.Title = grp.Title;

                        // if (!string.IsNullOrEmpty(grp.Description))
                        //  groupCreationInfo.Description = grp.Description;  
                        User owner  = null;
                       // SourceSite.Web.Context.Load(grp.Users);  


                        //clientContext.Load(siteGroup);
                        //clientContext.ExecuteQuery();
                        //clientContext.Load(siteGroup.Owner);
                        //clientContext.ExecuteQuery();

                        srcSite.Load(grp);
                        srcSite.ExecuteQuery();
                        srcSite.Load(grp.Owner);
                        srcSite.ExecuteQuery();
                        //load the client object list.RootFolder.Folders
                      // Principal p = grp.Owner; 

                        try
                        {
                            owner = TargetSite.Web.EnsureUser(grp.Owner.LoginName);
                        }
                        catch {   /*L'utente non essite */    }
                        // User member = TargetSite.Web.EnsureUser(grp.Owner.LoginName);

                        Group Tgroup = TargetSite.Web.SiteGroups.Add(groupCreationInfo);
                        Tgroup.Owner = owner;
                       // group.Users.AddUser(member);
                        Tgroup.Update();

                        TargetSite.ExecuteQuery();
                    }
                    }
                    catch { }


                }

            }

I also have the same error in other method, if I include group => group.Owner

into it

private static List<Group> GetGroups(ClientContext Context)
        {

            try
            {
                List<Group> gps = new List<Group>();
                Web web = Context.Web;
                GroupCollection groupColl = web.SiteGroups;
                Context.Load(groupColl,
                    groups => groups.Include(
                    group => group.Title,
                    group => group.Id ,
                   group=> group.OwnerTitle,                       
                   // group => group.Owner
                    ));
                Context.ExecuteQuery();
  • Where does grp come from? if it's from a different ClientContext (and it has to be, since you are not loading the group anywhere in the ClientContext you posted), you will see this error. – Dolgsthrasir Jun 16 '15 at 10:22
  • I think it's ok now. But I still have the same error! – hello B Jun 16 '15 at 10:33
  • What is SourceGroups? These groups are still from a different context. You cannot just load them in your new context. – Dolgsthrasir Jun 16 '15 at 10:39
  • ok. But why have I the same error in the other snipet? The second one should be correct. – hello B Jun 16 '15 at 10:43
  • That's strange indeed. Try loading the owner with all of these fields Context.Load(grp.Owner, o => o.Id, o => o.LoginName, o => o.Title, o => o.PrincipalType);. Maybe this helps. If not, then I am also out if ideas. – Dolgsthrasir Jun 16 '15 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.