GetAllSites using PageIterator, CreatePageIterator Does Not Accept Return Type of Type 'bool'
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:
I've also tried returning Task.FromResult(true); but this also does not work:
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_
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;
}
);
Hi, the issue is that the
GetAsGetAllSitesGetResponseAsyncmethod returns theGetAllSitesGetResponse(from theMicrosoft.Graph.Sites.GetAllSitesnamespace) instead of theSiteCollectionResponse. Change the type in thePageIteratorvar 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:
Could you check if you use GetAllSitesGetResponse from the Microsoft.Graph.Sites.GetAllSites namespace? Works fine on my side with the correct namespace.