Self referencing loop detected for property 'Value' with type 'xxx'. Path ''错误解决

问题:Self referencing loop detected for property 'Value' with type 'xxx'. Path ''

场景:.net core环境中使用release时,调用appsettings.json文件内容时报错,错误内容如上。

    源代码如下:

    Startup:services.Configure<TestClass>(_configuration.GetSection("xxx"));

    public class TestClass : IOptions<TestClass>

    {
      public TestClass Value => this;

      public double Lng { get; set; }

    }

    现对象改为如下可解决问题:

    public class TestClass : IOptions<TestClass>

    {

      [JsonIgnore]

      public TestClass Value => this;

      public double Lng { get; set; }

    }

如有疑问可咨询:

  

 

原文地址:https://www.cnblogs.com/colorchild/p/14524161.html