Microsoft Azure Active Directory 2.1.1 graph client has a bug:
In Azure AD we have user without manager.
When do batch requests to get specific users and expand manager we get Object null reference exception during response deserialization in case where no manager set:
at Microsoft.Azure.ActiveDirectory.GraphClient.Internal.DirectoryObject.set_manager(DirectoryObject value)
at lambda_method(Closure , Object , Object )
at System.Data.Services.Client.Metadata.ClientPropertyAnnotation.SetValue(Object instance, Object value, String propertyName, Boolean allowAdd)
at System.Data.Services.Client.Materialization.EntryValueMaterializationPolicy.MaterializeResolvedEntry(MaterializerEntry entry, Boolean includeLinks)
....
Seems this graph client is not open source we cannot fix that directly.
The code cause the problem:
//No manager for this user.
var query1 = activeDirectoryClient.Users.Where(t => t.ObjectId == "id1")
.Expand(t=>t.Manager);
var query2 = activeDirectoryClient.Users.Where(t => t.ObjectId == "id2")
.Expand(t => t.Manager);
var query3 = activeDirectoryClient.Users.Where(t => t.ObjectId == "id3")
.Expand(t=>t.Manager);
var query4 = activeDirectoryClient.Users.Where(t => t.ObjectId == "id4")
.Expand(t=>t.Manager);
// this line will throw exception.
var result = await activeDirectoryClient.Context.ExecuteBatchAsync(query1, query2, query3, query4);
Because ExecuteBatchAsync gets OperationResopnce and create pagedcollection for each response but initialization of this collection is not lazy. so if some error in one collection all responces will be blocked
Does anyone know how to workaround this?