failed to serialize the response in Web API

Solution 1:

For me this was a problem with circular referencing.

The accepted answer did not work for me because it only changes the behaviour of the JSON formatter, but I was getting XML when I called the service from the browser.

To fix this, I switched off XML and forced only JSON to be returned.

In the Global.asax file, put the following lines at the top of your Application_Start method:

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

Now only JSON results will be returned. If you need XML results, you will need to find a different solution.

Solution 2:

in your global.asax file, in the Application_start() method add this line:

GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;

I hope that helps you!