Web API Error: Failed to serialize the response body for content type

Error:

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

 
Workaround:
Just add the following code in WebApiConfig.cs –

var json = config.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
config.Formatters.Remove(config.Formatters.XmlFormatter);

Hope this helps!

Leave a Comment

Your email address will not be published. Required fields are marked *