问题描述
我正在使用Microsoft Graph .netcore SDK版本3.14向OneDrive for Business发出请求。 但是,无论何时有401未经授权的响应,我都会得到NullReferenceException而不是适当的错误响应。 我应该如何处理此错误,以确保NullReferenceException的根本原因是由于401? 以下是我删除OneDrive订阅的请求示例:
IGraphServiceSubscribedSkusCollectionRequestBuilder subscriptions = this.GetSubscriptions(credentials);
await subscriptions[webhookId]
.Request()
.DeleteAsync();
从提琴手那里,我看到响应是401。 下面的Ans是NullReferenceException的代码段。它不包含任何信息以指示由于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)
解决方法
这是由 SDK 中的错误引起的。请尝试升级到最新版本的sdk,看看问题是否仍然存在。
https://github.com/microsoftgraph/msgraph-sdk-dotnet-core/issues/167