I made the following action:
```
public object GetEntity(Guid id) {
var entity = _entityRepository.Get(id);
if (entity == null)
return NotFound();
return entity;
}
```
If I call it with wrong Guid, I get an error:
```
{
"Message": "An error has occurred.",
"ExceptionMessage": "The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.",
"ExceptionType": "System.InvalidOperationException"
"InnerException": {
"Message": "An error has occurred.",
"ExceptionMessage": "Self referencing loop detected for property 'ApplicationInstance' with type 'ASP.global_asax'. Path 'Request.Properties.MS_HttpContext.ApplicationInstance.Context'.",
"ExceptionType": "Newtonsoft.Json.JsonSerializationException"
}
}
```
If I change the return type of the method to `IHttpActionResult` is works. While it kind of make sense in retrospect, I think it is surprising and may lead to people wasting debugging time. Also it is slightly inconvenient (do I really need to Ok explicitly?).
I haven't checked if same happens for HttpResponseMessage, but if it is the same thing it wouldn't be great either.
```
public object GetEntity(Guid id) {
var entity = _entityRepository.Get(id);
if (entity == null)
return NotFound();
return entity;
}
```
If I call it with wrong Guid, I get an error:
```
{
"Message": "An error has occurred.",
"ExceptionMessage": "The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.",
"ExceptionType": "System.InvalidOperationException"
"InnerException": {
"Message": "An error has occurred.",
"ExceptionMessage": "Self referencing loop detected for property 'ApplicationInstance' with type 'ASP.global_asax'. Path 'Request.Properties.MS_HttpContext.ApplicationInstance.Context'.",
"ExceptionType": "Newtonsoft.Json.JsonSerializationException"
}
}
```
If I change the return type of the method to `IHttpActionResult` is works. While it kind of make sense in retrospect, I think it is surprising and may lead to people wasting debugging time. Also it is slightly inconvenient (do I really need to Ok explicitly?).
I haven't checked if same happens for HttpResponseMessage, but if it is the same thing it wouldn't be great either.