Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Issue: Json Deserialization Errors [1597]

$
0
0
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.


Comments: With Web API 2.0 or 2.1 in Visual Studio 2013, I tried to POST message with/without `[JsonIgnore]` on `Models` and the request body is like: { "Id": 5, "Name": "abc" } The response will always be 201 with bodies like (with `[JsonIgnore]`) {"Id":64,"Name":"abc"} or (without `[JsonIgnore]`) {"Id":74,"Name":"abc","Models":null} Since I cannot repo the issue with these versions so I tried WebAPI 1.0 in Visual Studio 2012. This time, I always got 500. It seems that the problem has been fixed somehow. However, you mentioned you are using Visual Studio 2013. So I am confused. Maybe there are other settings affecting? Could you please provide a sample project we can repo and work on to improve your debugging experience? Thanks.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>