As title says, I’ve got 500 Internal Server Error from GET request to an IQueryable action. The body of the error is empty. That error happens after my action returns result
I usually use the Global.asax to catch all error. Here is a code snip you can use
public void Application_Error(object sender, EventArgs e)
{
Exception exc = Server.GetLastError();
MvcApplication mvcApplication = sender as MvcApplication;
HttpRequest request = null;
if (mvcApplication != null) request = mvcApplication.Request;
}
This may be related to circular reference.
http://www.asp.net/web-api/overview/formats-and-model-binding/json-and-xml-serialization#handling_circular_object_references
Try adding the following code to Application_Start method in the Global.asax file:
var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.All;
I had the same problem, but the source of it was slightly different:
I set the CORS
policy incorrectly and that gives me 500 Internal server error
, but since CORS
was not working, the Access-Control-Allow-Origin
header was not presented in response and browser can't read the actual response
I solved it with ChromeDevTools option Copy as cURL
which allows me see the response and understand the source of error
I ran into this same issue. I found Kiran Challa's response helpful in getting the actual exception being thrown outside of my action.
To solve my issue, setting the ProxyCreationEnabled property of my context to false got me a step further.
In my scenario, my next exception was due to a circular reference in my models. After cleaning that up, the phantom 500 response was gone. Good luck if you haven't solved this yet!