This tutorial is related to development of Restful Web service using Microsoft Visual Studio for Web API project.
Exception Error Message:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml; charset=utf-8'.
Solution:
https://stackoverflow.com/questions/23098191/failed-to-serialize-the-response-in-web-api-with-json
Add the following code (c#) to global.asax under Application_Start method :
Scenario:
To simulate this exception error, follow the instructions in the tutorial below by starting a new project:
https://www.codeproject.com/Tips/1136105/Web-API-Return-List-of-Custom-Type-JSON
Exception Error Message:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml; charset=utf-8'.
Solution:
https://stackoverflow.com/questions/23098191/failed-to-serialize-the-response-in-web-api-with-json
Add the following code (c#) to global.asax under Application_Start method :
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings
.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
GlobalConfiguration.Configuration.Formatters
.Remove(GlobalConfiguration.Configuration.Formatters.XmlFormatter);
Scenario:
To simulate this exception error, follow the instructions in the tutorial below by starting a new project:
https://www.codeproject.com/Tips/1136105/Web-API-Return-List-of-Custom-Type-JSON
This post first appeared on IT-Sideways - Technology Social Media, please read the originial post: here