我正在使用Microsoft Graph Apps来检索或创建OneDrive文件。上周我做了一个POC,一切工作都很顺利。
现在,我试着将我们的App实现到一个现有的MVC网站中,但我遇到了奇怪的信息,即System.Threading.Tasks.Task无法找到。
at Microsoft.Graph.DriveRequest.<GetAsync>d__6.MoveNext()
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
at Microsoft.Graph.DriveRequest.GetAsync(CancellationToken cancellationToken)
at Microsoft.Graph.DriveRequest.GetAsync()
at BizzMine.Data.Repositories.OnlineEditorRepo.OnlineEditorRepository.<RequestSuccess>d__10.MoveNext() in C:\Users\geertverthe\Documents\repos\bizzmine\BizzMine.Data.Repositories\OnlineEditorRepo\OnlineEditorRepository.cs:line 89
我怀疑是System.Threading.Tasks.Task或者甚至是System.Web.Http的引用有问题,但我不确定。
这是我使用的(简单)代码。
Drive myDrive = await _graphServiceClient.Me.Drive.Request().GetAsync();
我的GraphServiceClient是这样构造的。
_graphServiceClient = new GraphServiceClient(
new DelegateAuthenticationProvider(async (request) => {
request.Headers.Authorization = new AuthenticationHeaderValue("bearer", _tokens.AccessToken);
await Task.FromResult<object>(null);
}));
.NET框架版本是4.6.1。
我确实有正确的同意权限,并且有一个有效的访问令牌。
请问我为什么会收到这样的错误,以及如何解决这个问题?
非常感谢您
经过大量的尝试,我设法解决我的问题。由于我们的解决方案和项目中包含了很多nuget包,其中一个是system.net.http。很明显,这个包里有一个NETStandard.Library.1.6.1。我觉得很奇怪,system.net.http有一个nuget包,因为这只是在框架本身。
将NETSTandard.Library.1.6.1升级到最新版本后,我可以删除system.net.http的nuget包。
在这之后,我唯一要做的改变是在项目中引用缺少的framework system.net.http,以及在一些项目中删除一个过时的绑定重定向。
现在工作正常了 :-)