Tuesday, December 23, 2014

[Resolved] WEBAPI ERROR using Json: The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml; charset=utf-8'.

hi lets see  how to resolve below error occurred while accessing web api for Json datatype :


 The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml; charset=utf-8'.



Solution:

go to global.asax file and in Application_Start() event add this below line.

GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
            GlobalConfiguration.Configuration.Formatters.Remove(GlobalConfiguration.Configuration.Formatters.XmlFormatter); 


After this u shud b able to run the webapi

Output:




No comments:

Post a Comment