pnpcore icon indicating copy to clipboard operation
pnpcore copied to clipboard

IList.ReIndexAsync() has no effect.

Open lucmoco opened this issue 6 months ago • 2 comments

Category

  • [x] Bug

Describe the bug

In a .NET 9.0 project, I'm trying to trigger the re-indexing of the SitePages library of a SharePoint Online website by using IList.ReIndexAsync(), but it has no effect, the indexing is not triggered.

The goal is to implement a work-around for a SharePoint bug where the number of likes (LikeCount) and the number of comments (CommentCount) are not regularly updated by the search engine.

Steps to reproduce

In a .NET project, run the following code:

var context = ...create your context;
var list = await context.Web.Lists.GetByServerRelativeUrlAsync("https://<tenant>.sharepoint.com/yourWebPath/SitePages");
await list.ReIndexAsync();

Then, in PowerShell, check if the indexing of the pages was triggered:

Get-PnPSearchCrawlLog -Filter "https://<tenant>.sharepoint.com/yourWebPath/SitePages"

You will see that the indexing is not triggered. If you start the indexing with PnP PowerShell instead, the indexing starts as expected:

Connect-PnPOnline -Url "https://<tenant>.sharepoint.com/yourWebPath" -Interactive -ClientId "your client ID"
Request-PnPReIndexList -Identity "SitePages" 

If you check with Get-PnPSearchCrawlLog as above, you will see that the indexing is triggered properly.

Expected behavior

When running IList.ReIndexAsync(), the list is re-indexed.

Environment details (development & target environment)

  • SDK version: 1.15.0
  • OS: Windows 11
  • SDK used in: ASP.Net Web app
  • Framework: .NET 9.0
  • Browser(s): N/A (background job)
  • Tooling: Visual Studio Professional 2022
  • Additional details: I've reproduced the problem with client-credentials and with ROPC authentication.

Additional context

By analyzing the network traffic, I could find out that the problem is likely a missing CSOM-Style Update() statement. Here is the request done by PnP.Core (doesn't work):

POST https://<tenant>.sharepoint.com/yourWebPath/_vti_bin/client.svc/ProcessQuery HTTP/1.1

<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="pnp core sdk"
  xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009">
  <Actions>
    <Method Name="SetFieldValue" Id="3" ObjectPathId="2">
      <Parameters>
        <Parameter Type="String">vti_searchversion</Parameter>
        <Parameter Type="Int32">738</Parameter>
      </Parameters>
    </Method>
    <Method Name="Update" Id="4" ObjectPathId="1"></Method>
  </Actions>
  <ObjectPaths>
    <Property Id="2" ParentId="1" Name="Properties" />
    <Identity Id="1" Name="<guid3>|<guid2>:site:<siteGuid>:web:<webGuid>:folder:<folderGuid>" />
  </ObjectPaths>
</Request>

We can see that two methods are being called:

  • Folder.SetFieldValue(...) - increases the value of the folder's vti_searchversion property.
  • Folder.Update() - commits the change to the folder's property.

However, for some reason this is not enough and the search is not triggered. If we have a look at the request done by the PowerShell cmdlet

Request-PnPReIndexList -Identity "SitePages"

we can see that it's similar but contains one more statement:

POST https://devsbb.sharepoint.com/sites/intranet_infochannels/_vti_bin/client.svc/ProcessQuery HTTP/1.1

<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName=".NET Library"
  xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009">
  <Actions>
    <Method Name="SetFieldValue" Id="23" ObjectPathId="18">
      <Parameters>
        <Parameter Type="String">vti_searchversion</Parameter>
        <Parameter Type="Int32">739</Parameter>
      </Parameters>
    </Method>
    <Method Name="Update" Id="24" ObjectPathId="12" />
    <Method Name="Update" Id="25" ObjectPathId="7" Version="529" />
  </Actions>
  <ObjectPaths>
    <Property Id="18" ParentId="12" Name="Properties" />
    <Identity Id="12" Name="<guid1>|<guid2>:site:<siteGuid>:web:<webGuid>:folder:<folderGuid>" />
    <Identity Id="7" Name="<guid1>|<guid2>:site:<siteGuid>:web:<webGuid>:list:<listGuid>" />
  </ObjectPaths>
</Request>

In addition to the Folder.SetFieldValue(...) and Folder.Update(), it also runs:

  • List.Update() - commits the changes to the list.

With that additional statement, the re-indexing of the library is started as expected.

lucmoco avatar Jun 05 '25 12:06 lucmoco

@lucmoco : you're correct, when checking the code in PnP PowerShell (which calls into PnP Framework for this) then we have this: https://github.com/pnp/pnpframework/blob/4ad153dcac4c863f2e62f3a359ff967fee4e512f/src/lib/PnP.Framework/Extensions/ListExtensions.cs#L438-L448.

Are you able to test if adding the list update call in https://github.com/pnp/pnpcore/blob/dev/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/List.cs#L1668 will fix your problem? If so, please submit a PR

jansenbe avatar Jun 13 '25 11:06 jansenbe

I discussed this with my project team and it's fine if I take the time to implement a fix+PR. I'll try to schedule this in the upcoming weeks.

lucmoco avatar Jun 18 '25 13:06 lucmoco

@jansenbe, I have submitted a pull request to fix this issue.

lucmoco avatar Jul 14 '25 14:07 lucmoco