I'm using the Microsoft Graph .netcore SDK version 3.14 to make requests to OneDrive For Business. However, whenever there's is a 401 Unauthorised response, I am getting the NullReferenceException instead of a proper error response. How should I handle this error so that I be sure that the root cause of NullReferenceException is due to 401? Below is the example of my request to delete a OneDrive subscription:
IGraphServiceSubscribedSkusCollectionRequestBuilder subscriptions = this.GetSubscriptions(credentials);
await subscriptions[webhookId]
.Request()
.DeleteAsync();
From the Fiddler, I can see that the response is 401. Ans below is a snippet of the NullReferenceException. It does not contain any information to indicate it failed due to 401.
Object reference not set to an instance of an object.
at Microsoft.Graph.HttpProvider.<SendAsync>d__18.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.BaseRequest.<SendRequestAsync>d__38.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.BaseRequest.<SendAsync>d__34`1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.SubscriptionRequest.<DeleteAsync>d__4.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
This was caused by a bug in the SDK. Please try to upgrade to the latest version of the sdk and see if the issue still occurs.
https://github.com/microsoftgraph/msgraph-sdk-dotnet-core/issues/167