locked
Newtonsoft.Json.JsonSerializationException:“Self referencing loop detected for property 'DeviceInfo' with type 'FireControl2.Models.DeviceInfoSet'. Path 'DataSet[0]'.” RRS feed

  • Question

  • User1849955458 posted

    公共无效ConfigureServices(IServiceCollection服务)
    {
    services.Configure <CookiePolicyOptions>(选项=>
    {
    // 拉姆达给确定定请求是否需要用户
    同意非必要cookie.options.CheckConsentNeeded =上下文=>真;
    options.MinimumSameSitePolicy = SameSiteMode.None;
    });

    .services.AddMvc()SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

    services.AddMvc()。AddJsonOptions(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

    services.AddSignalR();

    }

    Saturday, June 8, 2019 9:36 AM

All replies

  • User-1225169881 posted

    HI, 

    please try doing this in   Startup.cs 

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc().AddJsonOptions(options => {
            options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
        });
        services.AddEntityFramework().AddSqlServer().AddDbContext<IvoryPacketDbContext>(
            options => options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"])
        );
    }
    Sunday, June 9, 2019 3:07 AM
  • User-854763662 posted

    Hi laolaolulu ,

    Try to add decorate attributes on model class to control the serialization behavior on model or property level. To ignore the property:

    [JsonIgnore] 
    [IgnoreDataMember] 

    JsonIgnore is for JSON.NET and IgnoreDataMember is for XmlDCSerializer.  Reference : https://stackoverflow.com/a/18223985/10201850 

    Best Regards ,

    Sherry

    Monday, June 10, 2019 6:42 AM