Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
ActionResult<T> should convert to OkObjectResult or set StatusCode to 200 #27165
Comments
|
Thanks for contacting us. |
|
@snappyfoo setting the StatusCode would be a less dramatic change. There's a special case we would have to configure for |
|
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |


Currently if you return
Tin an action that returnsActionResult<T>it will create anObjectResult. The problem is that the StatusCode remains null rather than 200, even though the eventual response generated from it will be 200.This makes it confusing in, for example, an action filter, where a developer may only want to handle Ok object results on the executed context, including where
Tis returned directly. They may:OkObjectResultand find nullObjectResultwhich works but then find StatusCode is nullThey may not handle the result as they should as it's not obvious that a null StatusCode would eventually wind up as a 200 in the response. It seems to be an implementation detail that could easily change.
The assumption is always that returning
Twill result in a 200 OK (e.g. documentation mentions how you can leave out theTtype in aProducesResponseTypeattribute for 200 when usingActionResult<T>).Can this be further enforced by creating an
OkObjectResult(which will set StatusCode to 200 in its constructor)? If not, perhaps just anObjectResultas it currently does, but setting StatusCode to 200 with member initialisation?Is there perhaps room for improvement in documentation about any of this? Happy to be pointed to anything that makes it explicit how response status codes are created from result status codes including when the result status code is null etc.