Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Edited Feature: IHttpActionResult should be recognized dynamically (not based on an action return type) [1465]

$
0
0
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.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>