Analyzer: Warn that IResult should not be returned from Controller Actions #39692
Labels
analyzer
Indicates an issue which is related to analyzer experience
feature-mvc-execution-pipeline
Features related to how MVC executes a controller or razor page
✔️ Resolution: Won't Fix
Resolved because we decided not to change the behavior reported in this issue.
old-area-web-frameworks-do-not-use
*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Status: Resolved
Milestone
Today, with the new Microsoft.AspNetCore.Http.Results class is very easy to get confused and implement a Controller Action similar with that, or any other variation of the methods exposed by this class:
Also, is very easy to use an
Microsoft.AspNetCore.Http.IResult
custom implementation as a return of a controller action, like this:Both examples will not throw exception but will serialize the class. For the first example the action will return the following payload:
In rare situations it will be the expected behavior. With that, we should add an analyzer that detects if the action return an
Microsoft.AspNetCore.Http.IResult
and fail/warn. It might be also possible provide a code fix suggestion in cases where theControllerBase
has a similar method, eg:From:
To:
The text was updated successfully, but these errors were encountered: