Microsoft Graph Page Iterator async/ non-async lambda function

17 hours ago 3
ARTICLE AD BOX

Does anybody know why in the following block of code, inside the lambda function of the PageIterator I receive the following error:

Cannot implicitly convert type 'bool' to 'System.Threading.Tasks.Task<bool>' public async Task<IEnumerable<EmployeeViewModel>> GetMembersOf(GroupQueryViewModel model) { var graphClient = await GetGraphClient(); var filter = GetFilterQuery(model); var groups = await graphClient.Groups.GetAsync(requestConfiguration => { requestConfiguration.QueryParameters.Filter = filter; requestConfiguration.QueryParameters.Select = ["id"]; }); var groupIds = new List<string>(); var pageIterator = PageIterator<Group, GroupCollectionResponse>.CreatePageIterator( graphClient, groups, (group) => { groupIds.Add(group.Id); return true; }, (req) => { return req; }); await pageIterator.IterateAsync(); ConcurrentDictionary<string, EmployeeViewModel> allMembers = new ConcurrentDictionary<string, EmployeeViewModel>(); Parallel.ForEachAsync(groupIds, async (id, cancellationToken) => { var members = await graphClient.Groups[id].Members.GetAsync(requestConfiguration => { requestConfiguration.QueryParameters.Select = [ "userPrincipalName", "displayName", "mail", "givenName", "surname", "photo" ]; }); var iterator = PageIterator<User, UserCollectionResponse>.CreatePageIterator( graphClient, members, (user) => { if (allMembers.ContainsKey(user.Id)) return true; var nameParts = user.UserPrincipalName.Split('@'); EmployeeViewModel employee = new EmployeeViewModel { /* Creation logic */ }; allMembers.TryAdd(user.Id, employee); return true; }, (req) => { return req; }); await iterator.IterateAsync(); }); return allMembers.Values; }

I can not seem to find a way around it.
The PageIterator correctly states that it expects a Function<User, bool>. Inside of the lambda there is no async/ await call so I do not understand why it expects the return value to be Task.

I tried this:

async (user) => { /* Same logic */ }

But this is also faulty and generates a compiler error.
Does anybody have any idea what I can do to fix it? My guess is that this comes from the context it runs in, but I can not put my fingers on it. Since the first PageIterator, for Groups works fine, my only guess is that it comes from the run inside the foreach statement. I have tried swapping the

Parallel.ForEach(...)

with

foreach(...)

But nonetheless, the same effect.

Read Entire Article