microsoftgraph / microsoftgraph/msgraph-sdk-dotnet

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

Open
#3,001 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Question: SDK Status: Needs investigation
Dominant language
C#
Stars
789
Forks
264
Avg merge
15h 17m
Merged PRs (30d)
3

Description

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_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided GetAllSitesGetResponse example and inspect the CreatePageIterator entry point in SDK 5.93.0, reproducing it on .NET 8 or .NET 9. Compare the callback signatures with the bool and Task callbacks shown; done when the callback compiles and page iteration works for the multi-page sites case.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.