Page.cs SaveAsync fails on a big SitePages list
See original GitHub issueCategory
- Bug
Describe the bug
I use PnP Provisioning to create Pages in the SitePages library. It currently fails with a nullreference exception, on my production sitecollection that has more than 5000 items in there. Same code runs on a site collection with less files in the library, all works.
Steps to reproduce
- Have a SitePages list with >5000 items (mine has 5950)
- Run a PnP Provisioning script that creates a page
- Have it fail 😉
Expected behavior
Page should be created without nullreference.
Additional context
Problem exists in this method: https://github.com/pnp/pnpcore/blob/189ca6153db0e77e9e4a2cbf12d93a7945ee5521/src/sdk/PnP.Core/Model/SharePoint/Pages/Internal/Page.cs#L1421
And manifests at this point, where PageListItem
is null
https://github.com/pnp/pnpcore/blob/189ca6153db0e77e9e4a2cbf12d93a7945ee5521/src/sdk/PnP.Core/Model/SharePoint/Pages/Internal/Page.cs#L1518
My 2 cents
You are doing this: https://github.com/pnp/pnpcore/blob/189ca6153db0e77e9e4a2cbf12d93a7945ee5521/src/sdk/PnP.Core/Model/SharePoint/Pages/Internal/Page.cs#L1761-L1779
As far as I can see, it essentially does a big query to SharePoint to fetch ALL matching items. The code before already established a mypagename.aspx
which is unique in that specific list. I don’t see why we need to query to full list here just to get the ListItem associated with the file.
Can’t it be simpler like
file = list.ParentWeb.GetFileByServerRelativeUrl(@"path\to\mypagename.aspx");
clientContext.Load(docSet.ListItemAllFields);
await clientContext.ExecuteQueryAsync();
Using GetFileByServerRelativeUrl does not trip over a big list.
Also, I might be totally looking at this wrong. So any other insights are appreciated. My code is failing in production so I can spend time on this to make it better if someone can provide directions.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (9 by maintainers)
Top GitHub Comments
@YannickRe : Your change was merged, all the tests did succeed. Thanks!
@jansenbe You’ve got mail!