I'm using Microsoft Graph API library (C#) and wondering if anyone has experienced this:
Many of my graph API calls time out from time to time.
This can happen to any API call, from getting current user profile to getting sharepoint documents, and so on.
I've tried updating Microsoft Graph API and dependent Nuget packages to the latest versions, but it doesn't help.
To clarify, this application is a Windows console application. On Azure side, it is registered as a native application. As a test application, it is a single-threaded application. No concurrency, race conditions involved. Code logic is as simple as
- User logs in.
- The program makes a Graph API call (shown in eg.1) to get user's profile and this API call times out.
eg 1.
var currentUser = graphClient.Me.Request().GetAsync().Result;
eg 2.
var site = _graphClient.Sites[SharePointSiteId].Request().GetAsync().Result;
The symptom is after a minute or two, it throws an AggregationException(because of TPL) which includes a TimeOutException.
No unauthorized exception.
I want to know what could be the possible cause and how I can avoid that.
UPDATE: Here's a screenshot when the exception happens.
UPDATE 2: I've tried replacing all the API calls to use "await" directly to wait for results. because this example code is a console application. I put
static void Main(string[] args)
{
// using Stephen Cleary's nuget package: Nito.AsyncEx.Tasks
MainImp().WaitAndUnwrapException();
}
static async Task MainImp()
{
// ...
// Graph API calls
This exception is still thrown from this simple API call:
var currentUser = await graphClient.Me.Request().GetAsync();
An unhandled exception of type 'Microsoft.Graph.ServiceException' occurred in mscorlib.dll Additional information: Code: timeout
Here's the full call stack
at Microsoft.Graph.HttpProvider.d__19.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.Graph.HttpProvider.d__18.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.Graph.BaseRequest.d__35.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.Graph.BaseRequest.d__31
1.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.Graph.UserRequest.<GetAsync>d__6.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 System.Runtime.CompilerServices.TaskAwaiter
1.GetResult() at SharePointConsoleApp.Program.d__14.MoveNext() in D:\TestProjects\SharePointConsoleApp\Program.cs:line 133 --- 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 Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task) at SharePointConsoleApp.Program.Main(String[] args) in D:\TestProjects\SharePointConsoleApp\Program.cs:line 50 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()