I'm new to Web API and I've learned a lot throug forums and pluralsight-training. I'm developing a page to show large amount of data in a tabular form (project started with an Empty ASP.Net 4.0 Web Site, not a project or MVC application).
When I call apis which return data which has one or two properties in each row, it returns fine. But when I call an api which return large amount of data, a stack overflow exception is thrown. I assume this is due to circular references which I had problems
withe before as well. Can someone please help me how to debug this or to solve this. I have the following global configurations setup.
var config = GlobalConfiguration.Configuration;
config.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize;
config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
// Code that runs on application startup
// Code that runs on application startup
RouteTable.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = System.Web.Http.RouteParameter.Optional }
);
Any help really appreciated.
Thanks,
Amila
Please mark this reply as an Answer, if you find it useful. Thanks :) Happy Coding.....
amilarox
Member
144 Points
59 Posts
Get Circular reference serialized using Newtonsoft.json
Dec 14, 2012 12:45 PM|LINK
Hi All,
I'm new to Web API and I've learned a lot throug forums and pluralsight-training. I'm developing a page to show large amount of data in a tabular form (project started with an Empty ASP.Net 4.0 Web Site, not a project or MVC application).
When I call apis which return data which has one or two properties in each row, it returns fine. But when I call an api which return large amount of data, a stack overflow exception is thrown. I assume this is due to circular references which I had problems withe before as well. Can someone please help me how to debug this or to solve this. I have the following global configurations setup.
var config = GlobalConfiguration.Configuration; config.Formatters.XmlFormatter.SupportedMediaTypes.Clear(); config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize; config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects; // Code that runs on application startup // Code that runs on application startup RouteTable.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = System.Web.Http.RouteParameter.Optional } );Any help really appreciated.
Thanks,
Amila
http://amilaug.blogspot.co.uk/
GorillaMann
Member
117 Points
332 Posts
Re: Get Circular reference serialized using Newtonsoft.json
Mar 02, 2013 04:26 PM|LINK
see this:
http://johnnycode.com/2012/04/10/serializing-circular-references-with-json-net-and-entity-framework/