【问题标题】:Method not found: 'Void Microsoft.Graph.BaseRequest.set_Method(System.String)'找不到方法:'无效 Microsoft.Graph.BaseRequest.set_Method(System.String)'
【发布时间】:2021-12-27 19:45:38
【问题描述】:

我正在使用Microsoft.Graph 进行一些Sharepoint 操作,我们以列出活跃用户为例。考虑一下我正在使用的以下 sn-ps:

public async Task<IList<User>> GetUsers()
{
    GraphServiceClient graphClient = await GetGraphServiceClient();
    var users = await graphClient.Users.Request().GetAsync();
    return users;
}

GetGraphServiceClient 方法创建Microsoft.Graph.GraphServiceClient 的实例,其定义如下:

public async Task<GraphServiceClient> GetGraphServiceClient()
{
    return new GraphServiceClient(new DelegateAuthenticationProvider(async (requestMessage) =>
    {
        requestMessage.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", await GetAccessToken());

    }));
}

我得到了一个有效的访问令牌,但是await graphClient.Users.Request().GetAsync(); 行抛出了一个错误,上面写着

找不到方法:'Void Microsoft.Graph.BaseRequest.set_Method(System.String)'。

堆栈跟踪

在 Microsoft.Graph.GraphServiceUsersCollectionRequest.d__4.MoveNext() 在 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine) 在 Microsoft.Graph.GraphServiceUsersCollectionRequest.GetAsync(CancellationToken cancelToken) 在 Microsoft.Graph.GraphServiceUsersCollectionRequest.GetAsync() 在 myNamespace.GraphAPIHelper.d__3.MoveNext()

以下是项目中使用的 graphSDK 和 SharePoint 客户端的版本:

有人可以帮我确定导致问题的原因吗?我已经交叉检查并验证了租户 ID、客户端 ID 和访问令牌。有些东西不见了,但没有得到任何线索。

【问题讨论】:

    标签: c# .net sharepoint microsoft-graph-api sharepoint-online


    【解决方案1】:

    今天我遇到了类似的情况。我不使用 Sharepoint,但想使用 Graph 查找用户并收到错误消息 Method not found: 'Void Microsoft.Graph.BaseRequest.set_Method(System.String)'. 对我来说幸运的是,我能够调试另一个解决方案,其中几乎用于查询用户的确切代码实际上可以工作。通过比较两种解决方案,我终于在 nuget 包列表中发现了一个差异。错误的解决方案引用了 Microsoft.Graph.Core 和 Microsoft.Graph。工作解决方案仅引用了 Microsoft.Graph。删除对 Microsoft.Graph.Core 的引用为我解决了这个问题。不过不要问我为什么。

    【讨论】:

      【解决方案2】:

      您必须将核心版本更改为 1.**

      【讨论】:

      • 你能补充更多细节吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-14
      • 2015-08-05
      • 2018-12-14
      • 2021-06-17
      • 2021-09-12
      • 2018-01-14
      • 2019-03-11
      相关资源
      最近更新 更多