msgraph-sdk-dotnet icon indicating copy to clipboard operation
msgraph-sdk-dotnet copied to clipboard

GetAllSites using PageIterator, CreatePageIterator Does Not Accept Return Type of Type 'bool'

Open jluthi opened this issue 3 months ago • 3 comments

Describe the bug

Hi, I am trying to get all sites for our tenant and loop through them to find certain ones. We have more than 200 sites, a lot of them personal. I learned that using the PageIterator is the best way to go about this. However, I cannot for the life of me get it to work with the last stable version of the SDK with either .NET 8 or .NET 9.

The following is my code:

private async Task<List> GetAllSitesGetResponse()
{

   var allSites = new List<Site>();

   var firstPage = await _graphClient.Sites.GetAllSites.GetAsGetAllSitesGetResponseAsync();

   var pageIterator = PageIterator<Site, SiteCollectionResponse>
       .CreatePageIterator(
           _graphClient,
           firstPage,
           (site) =>
           {
               allSites.Add(site);
               return true;
           },
           // This is optional func
           (req) =>
           {
               return req;
           }
       );

   await pageIterator.IterateAsync();

   return allSites;
}

And this error I get in Visual Studio:

Image

I've also tried returning Task.FromResult(true); but this also does not work:

Image

Would appreciate any help. We are desperate to get this project wrapped up. Much appreciated!

Expected behavior

The CreatePageIterator's callback parameter should accept my return boolean type of 'true'.

How to reproduce

Just try the code I provided above with the following SDK version and .NET 8 or .NET 9.

SDK Version

5.93.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ```
</details>


### Configuration

Windows 11 24H2

### Other information

_No response_

jluthi avatar Sep 25 '25 16:09 jluthi

Hi, the issue is that the GetAsGetAllSitesGetResponseAsync method returns the GetAllSitesGetResponse (from the Microsoft.Graph.Sites.GetAllSites namespace) instead of the SiteCollectionResponse. Change the type in the PageIterator

var pageIterator = PageIterator<Site, GetAllSitesGetResponse>
       .CreatePageIterator(
           _graphClient,
           firstPage,
           (site) =>
           {
               allSites.Add(site);
               return true;
           },
           // This is optional func
           (req) =>
           {
               return req;
           }
       );

MartinM85 avatar Sep 26 '25 04:09 MartinM85

Hi, the issue is that the GetAsGetAllSitesGetResponseAsync method returns the GetAllSitesGetResponse (from the Microsoft.Graph.Sites.GetAllSites namespace) instead of the SiteCollectionResponse. Change the type in the PageIterator

var pageIterator = PageIterator<Site, GetAllSitesGetResponse>
       .CreatePageIterator(
           _graphClient,
           firstPage,
           (site) =>
           {
               allSites.Add(site);
               return true;
           },
           // This is optional func
           (req) =>
           {
               return req;
           }
       );

Thank you but same problem sadly:

Image

jluthi avatar Sep 26 '25 22:09 jluthi

Could you check if you use GetAllSitesGetResponse from the Microsoft.Graph.Sites.GetAllSites namespace? Works fine on my side with the correct namespace.

MartinM85 avatar Sep 27 '25 07:09 MartinM85