I've had a really bad time debugging an ASP.NET Web API project I've been working on because of Json Deserialization errors which happened because of circular references on my models. For example:
```
public class Make
{
[Key]
public int Id { get; set; }
[Required]
[MaxLength(50)]
public string Name { get; set; }
[JsonIgnore]
public virtual ICollection<Model> Models { get; set; }
}
public class Model
{
[Key]
public int Id { get; set; }
[Required]
[MaxLength(50)]
public string Name { get; set; }
[Required]
public int MakeId { get; set; }
[ForeignKey("MakeId")]
public virtual Make Make { get; set; }
}
```
I didn't even know the JsonIgnore annotation existed! And my controller was returning HTTP Code 500 (Internal Server Error) over and over again. The only way I was able to find out what was going on was __INTELLITRACE__. Good thing I have Visual Studio 2013 Ultimate at work right? But most people don't. So I would like to submit a request for an error message to go along with that HTTP 500. I would rather have my application halt to a stop and find a bug early than having to lose hours finding an obscure error.
It's also tricky when you have a virtual IdentityUser, but that one fails for a different reason.
```
public class Make
{
[Key]
public int Id { get; set; }
[Required]
[MaxLength(50)]
public string Name { get; set; }
[JsonIgnore]
public virtual ICollection<Model> Models { get; set; }
}
public class Model
{
[Key]
public int Id { get; set; }
[Required]
[MaxLength(50)]
public string Name { get; set; }
[Required]
public int MakeId { get; set; }
[ForeignKey("MakeId")]
public virtual Make Make { get; set; }
}
```
I didn't even know the JsonIgnore annotation existed! And my controller was returning HTTP Code 500 (Internal Server Error) over and over again. The only way I was able to find out what was going on was __INTELLITRACE__. Good thing I have Visual Studio 2013 Ultimate at work right? But most people don't. So I would like to submit a request for an error message to go along with that HTTP 500. I would rather have my application halt to a stop and find a bug early than having to lose hours finding an obscure error.
It's also tricky when you have a virtual IdentityUser, but that one fails for a different reason.