You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 6.0调用MS Graph Beta API遇Request方法不存在错误求助

解决TiIndicatorsRequestBuilder无Request方法的问题

问题根源

Microsoft Graph SDK v5(包括Beta版5.x系列)重构了API调用范式,彻底移除了旧版中的Request()方法,同时Microsoft.Graph.Auth包已被官方弃用,完全不兼容v5版本的Graph SDK,这是导致报错的核心原因。

分步解决方案

1. 调整包依赖

卸载Microsoft.Graph.Auth,改用Microsoft.Identity.Client处理身份验证,确保Graph相关包版本匹配:

  • 保留Microsoft.Graph.Beta(建议升级至最新5.x预览版,保证API兼容性)
  • 保留Microsoft.Graph.Core(需与Beta包版本保持兼容)
  • 安装Microsoft.Identity.Client(使用最新稳定版即可)

2. 修改API调用代码

替换旧版报错写法:

// 旧版(报错代码)
var tiIndicators = await graphClient.Security.TiIndicators.Request().GetAsync();

改为v5适配的写法:

// 确保已通过Microsoft.Identity.Client完成graphClient的身份初始化
var tiIndicators = await graphClient.Security.TiIndicators.GetAsync();

3. 核对命名空间

确保代码顶部引用了正确的命名空间:

using Microsoft.Graph.Beta;
using Microsoft.Graph.Beta.Models;
using Microsoft.Identity.Client;

进阶用法(筛选活跃指标)

如果需要筛选活跃状态的TI指标,可通过RequestConfiguration添加查询参数:

var requestConfig = new SecurityTiIndicatorsRequestConfiguration
{
    QueryParameters = new SecurityTiIndicatorsQueryParameters
    {
        Filter = "status eq 'active'",
        Select = new[] { "id", "indicatorType", "indicatorValue", "expirationDateTime" }
    }
};

var activeTiIndicators = await graphClient.Security.TiIndicators.GetAsync(requestConfig);

内容的提问来源于stack exchange,提问作者Rubeste

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 05:25:41