【问题标题】:RedisClientManager, An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dllRedisClientManager,在 mscorlib.dll 中发生“System.StackOverflowException”类型的未处理异常
【发布时间】:2015-02-20 21:33:38
【问题描述】:

我正在使用 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],因为嵌套循环,(优惠券包含用户) 我找不到什么问题?

【问题讨论】:

    标签: c# asp.net servicestack.redis


    【解决方案1】:

    我找到了适合我的解决方案。 ApplicationUser 对象有 Coupon 并且 Coupon 有 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; }
    }
    

    现在我可以忽略 Coupon 属性,因此 Servis.Stack redisClientManager 可以序列化对象。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多