I wanted to use the PageIterator in my project, and it works perfectly until I wanted to take out group members from AzureAD. No matter what I do, the PageIterator failes with 'The Parsable does not contain a collection property'.
List<User> users = new();
var result = await graphClient.Groups[groupId].Members.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Top = 2;
// I only do this to force pageing, will not be on final version
});
var pageIterator = PageIterator<User, DirectoryObjectCollectionResponse>
.CreatePageIterator(graphClient, result,
(m) =>
{
users.Add(m);
return true;
});
await pageIterator.IterateAsync();
My code forces 2 items. It's only because I, in a desperate attempt, tries to figure out what is wrong with my code.
I am left clueless on what's wrong here and any help would be awesome.
I reproduced your issue in my side and I changed the code like below:
The issue happened at the response type. List Member API will return
directoryObjectas the response, but in your code, you hadPageIterator<User, DirectoryObjectCollectionResponse>which causing the error.By the way, if we only want to get user members, then we may change code like this: