Azure Graph API calls throwing Exception The context is already tracking a different entity with the same resource Uri

254 views Asked by At

We are using Azure Graph API client library version 2.1.1.0. Our application tries to validate the user roles at the time of login. While doing this ad client. Following call seems to be throwing an exception. Any help in this regard is highly appreciated.

Call:

       adClient.Users
            .Expand(_ => _.MemberOf)
            .Where(_ => _.ObjectId == objectId)
            .ExecuteAsync()
            .Result;
       adClient.DirectoryRoles
            .Expand(_ => _.Members)
            .ExecuteAsync()
            .Result;.

Exception Details: ---> (Inner Exception #0) System.InvalidOperationException: The context is already tracking a different entity with the same resource Uri. at System.Data.Services.Client.EntityTracker.InternalAttachEntityDescriptor(EntityDescriptor entityDescriptorFromMaterializer, Boolean failIfDuplicated) at System.Data.Services.Client.AtomMaterializerLog.ApplyToContext() at System.Data.Services.Client.MaterializeAtom.MoveNextInternal() at System.Data.Services.Client.MaterializeAtom.MoveNext() at System.Linq.Enumerable.d__941.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Microsoft.Azure.ActiveDirectory.GraphClient.Extensions.PagedCollection2..ctor(DataServiceContextWrapper context, QueryOperationResponse1 qor) at Microsoft.Azure.ActiveDirectory.GraphClient.Extensions.DataServiceContextWrapper.<>c__DisplayClass4c2.b__4a(IAsyncResult r) at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.ActiveDirectory.GraphClient.Extensions.DataServiceContextWrapper.d__4e2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.ActiveDirectory.GraphClient.Extensions.ReadOnlyQueryableSet2.<b__0>d__2.MoveNext()<---

0

There are 0 answers