pnpcore icon indicating copy to clipboard operation
pnpcore copied to clipboard

Issue on loading RoleAssignments of list items

Open gopaldahal opened this issue 1 year ago • 3 comments

Category

  • [x] Bug

Describe the bug

Item loaded using LoadListDataAsStreamAsAsync is not able to load with Roledefinitions on next query execution. It was on working state on version 1.3. However throws unhandled exception on every consequent versions.

Steps to reproduce

  item.RoleAssignments.LoadBatchAsync(context.CurrentBatch, x => x.RoleDefinitions).Wait();
     context.Execute();

Expected behavior

Redefinitions must be loaded with out failure

Environment details (development & target environment)

  • SDK version: [1.7 ]
  • OS: [Windows 10 ]
  • SDK used in: [Console App ]
  • Framework: [.NET Framework v4.7.1 ]
  • Tooling: [Visual Studio 2019]

Additional context

Thanks for your contribution! Sharing is caring.

gopaldahal avatar Jul 27 '22 11:07 gopaldahal

@gopaldahal : can you provide a more detailed repro? Also an error message and stack trace will help identify what goes wrong.

jansenbe avatar Aug 22 '22 13:08 jansenbe

@gopaldahal : closing this one, if the issue still is there, please re-open and provide the needed details to help troubleshoot the issue. Thx for using PnP Core SDK!

jansenbe avatar Sep 05 '22 11:09 jansenbe

@jansenbe

I am also facing the same issue.

public static IEnumerable<IListItem> GetListItems(IList parentList, List<string> parentFields, string folderRelativeUrl, string queryString, ViewScop scope = ViewScop.DefaultValue) {
            try {
                var viewFieldsString = string.Join("", parentFields.Select(d => "<FieldRef Name='" + d + "'/>").ToArray());
                int rowLimit = 1000;
                string nextPage = null;
                string viewXml = "<View Scope='" + scope.ToString() + "'>" +
                    (string.IsNullOrEmpty(viewFieldsString) ? "" : "<ViewFields>" + viewFieldsString + "</ViewFields>") +
                    "<RowLimit Paged='TRUE'>" + rowLimit + "</RowLimit>" +
                    queryString +
                   "</View>";
                do {
                    #region LoadListDataAsStreamAsync
                    var loadOption = new RenderListDataOptions() {
                        ViewXml = viewXml,
                        RenderOptions = RenderListDataOptionsFlags.ListData,
                        Paging = nextPage ?? null,
                        DatesInUtc = true,
                        FolderServerRelativeUrl = folderRelativeUrl
                    };
                    var output = parentList.LoadListDataAsStreamAsync(loadOption).Result;
                    if (output.ContainsKey("NextHref")) {
                        nextPage = output["NextHref"].ToString().Substring(1);
                    }
                    else {
                        nextPage = null;
                    }
                    #endregion

                }
                while (!string.IsNullOrEmpty(nextPage));
                var result = parentList.Items.AsRequested();
                return result;
            }
            catch (Exception ex) {
                throw;
            }
        }

Above method return the item, and after loading roleAssignments,

item.RoleAssignments.LoadBatchAsync(context.CurrentBatch, x => x.RoleDefinitions).Wait();

it throw the below exception.

ArgumentNullException: Value cannot be null.
Parameter name: member
   at System.Linq.Expressions.Expression.MakeMemberAccess(Expression expression, MemberInfo member)
   at PnP.Core.Model.BaseDataModelCollection`1.ConvertExpressionToParent(Expression`1[] expressions)
   at PnP.Core.Model.BaseDataModelCollection`1.LoadBatchAsync(Batch batch, Expression`1[] expressions)
   at PnPCoreHandler.PnPCoreCommonUtils.GetItemProperties(String siteUrl, String listName, List`1 filters)

Note: This issue occur while upgrading Pnp.core to 1.7.17.0.

rojin55 avatar Sep 20 '22 11:09 rojin55

@gopaldahal , @rojin55 : sorry for the late reply, but below is how this should be used (works in my testing):

await item.LoadBatchAsync(context.CurrentBatch, x => x.RoleAssignments.QueryProperties(x => x.RoleDefinitions));

This is because the RoleAssignments was not yet loaded after the LoadListDataAsStreamAsync call.

Closing issue now. Please create a new one if you still have issues using the current release.

jansenbe avatar Jan 20 '23 19:01 jansenbe