RedisClientManager,类型' System.StackOverflowException'的未处理异常发生在mscorlib.dll中

时间:2015-02-18 12:39:01

标签: c# asp.net servicestack.redis

我正在使用RedisClientManager并且我正在使用尝试设置对象时,mscorlib.dll 错误中出现未处理的“System.StackOverflowException”类型错误

client.Set<ApplicationUser>(user.Id, user);

用户:

public class ApplicationUser : IdentityUser
{        
    public string Name { get; set; }
    public string Surname { get; set; }
    public DateTime? BirthDay { get; set; }
    public int BirthPlace { get; set; }
    public int TeamId { get; set; }
    public int AvatarId { get; set; }
    public string Address { get; set; }
    public DateTime RegisterationDate { get; set; }
    public DateTime CodeSendDate { get; set; }
    public string ActivationCode { get; set; }
    public string PasswordResetToken { get; set; }
    public string FacebookAvatar { get; set; }
    public string FacebookId { get; set; }
    public bool UseFacebookAvatar { get; set; }
    public string IpAddress { get; set; }

    public virtual Avatar Avatar { get; set; }

    public ApplicationUser()
    {
        this.Coupons = new HashSet<Coupon>();
    }

    [JsonIgnore]
    public virtual ICollection<Coupon> Coupons { get; set; }
}

序列化ApplicationUser时出错,我尝试在嵌套循环的ICollection上添加[JsonIgnore],(优惠券包含用户) 我找不到什么问题?

1 个答案:

答案 0 :(得分:0)

我找到了适用于我的解决方案。 ApplicationUser对象有优惠券和优惠券有ApplicationUser(多对多) 所以序列化无限循环。

我添加[IgnoreDataMember]

public class ApplicationUser : IdentityUser
{        
    public string Name { get; set; }
    public string Surname { get; set; }
    public DateTime? BirthDay { get; set; }
    public int BirthPlace { get; set; }
    public int TeamId { get; set; }
    public int AvatarId { get; set; }
    public string Address { get; set; }        
    public DateTime RegisterationDate { get; set; }        
    public DateTime CodeSendDate { get; set; }
    public string ActivationCode { get; set; }
    public string PasswordResetToken { get; set; }
    public string FacebookAvatar { get; set; }
    public string FacebookId { get; set; }
    public bool UseFacebookAvatar { get; set; }
    public string IpAddress { get; set; }        

    public virtual Avatar Avatar { get; set; }


    public ApplicationUser()
    {
        this.Coupons = new HashSet<Coupon>();
    }

    [IgnoreDataMember]
    public virtual ICollection<Coupon> Coupons { get; set; }
}

现在我可以忽略优惠券属性,因此Servis.Stack redisClientManager可以对该对象进行连续处理。