I’m completely lost on what could be causing this.
I have an ASP.Net MVC 4 RC application and I have a set of Web API controllers. I’m trying to return an object that contains a set of child objects in an IList. Whenever I request the object I get a 500 error back on the browser with no noticeable exception thrown in the debugger. I’ve tried putting an Application_Error handler in the global.asax and no error is caught there either.
It doesn’t matter whether the List is an actual database relation or just a hard coded list of strings, in either case the request fails. If i set the list to null the request succeeds.
If i remove the list the request succeeds and I get an XML (or JSON) representation of the object.
I’ve also tried this line –
GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
To capture the actual exception and still get nothing back.
Here’s the current object
public class Authority : IEntity
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual string Address1 { get; set; }
public virtual string Address2 { get; set; }
public virtual string City { get; set; }
public virtual string County { get; set; }
public virtual string State { get; set; }
public virtual string ContactPostalCode { get; set; }
//public virtual IList<PostalCode> PostalCodes { get; set; }
public virtual IList<string> RandomTrash { get; set; }
public VPA()
{
//PostalCodes = new List<PostalCode>();
RandomTrash = new List<string> {"foo"};
}
}
Note the commented out PostalCodes collection – that is a real many to many database relationship. I commented it out and replaced it with the dummy “RandomTrash” collection and the failure seems to be the same.
I have a feeling this is a serialization failure somehow but I can’t figure out how to avoid it. If it helps I’m using NHibernate as the ORM.
Has anyone seen this?
Answering my own question in case anyone runs into this again.
It ended up being Serialization following the grid in a loop. To fix i added 2 attributes to each looping reference in one of the models.
[IgnoreDataMember] For the XML Serializer
[JsonIgnore] For JSON.Net’s Serializer.
I added those the PostalCode class on the IList property.
There may be a better solution. The downside of this one is it makes my API one sided. I can request an Authority and get all of it’s postal codes, but i can’t request a postal code and get all of it’s Authorities.