【问题标题】:net core api newtonsoft.json Self referencing loop detected for property 'Client' with type 'Microsoft.Graph.GraphServiceClient'. Path 'Invitations'net core api newtonsoft.json 检测到类型为“Microsoft.Graph.GraphServiceClient”的属性“客户端”的自引用循环。路径“邀请”
【发布时间】:2021-09-11 01:10:15
【问题描述】:

我将GraphServiceClient存储在会话中(因为我需要在其他请求中使用它):

HttpContext.Session.SetObject("graphClient", _graphServiceClient);

GraphServiceClient是一个Object,所以我扩展了Session:

public static class SessionExtensions
    {
        public static void SetObject(this ISession session, string key, object value)
        {
            session.SetString(key, JsonConvert.SerializeObject(value));
        }

        public static T GetObject<T>(this ISession session, string key)
        {
            var value = session.GetString(key);
            return value == null ? default(T) : JsonConvert.DeserializeObject<T>(value);
        }
    }

尝试发布请求时,我收到以下 401 状态错误

“检测到具有类型的属性“客户端”的自引用循环 'Microsoft.Graph.GraphServiceClient'。路径“邀请”。”

【问题讨论】:

  • 为了能够重现您的问题,我们需要查看导致问题的代码和有效负载。 BR
  • 您为什么要尝试存储客户端而不仅仅是令牌?您应该只需要存储令牌,然后在需要时创建客户端。

标签: asp.net-core json.net microsoft-graph-api asp.net-core-webapi


【解决方案1】:

正如 Marc LaFleur 所建议的,我通过存储令牌解决了这个问题

【讨论】:

    猜你喜欢
    • 2021-12-26
    • 1970-01-01
    • 2021-07-31
    • 2020-03-29
    • 2018-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-11
    • 2017-02-13
    相关资源
    最近更新 更多