You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to upgrade AutoWrapper from 4.5 to 5.0 in order to work around the problems reported in issue #133.
In doing so, I've found a problem that does not seem to exist in 4.5, and am hoping you can provide some advice.
The problem is that, when using the controller's StatusCode() method to return a status code, if the controller or action has the [Produces("application/json")] attribute, the result is returned as a string rather than an object. As seen in the details of issue #133, this does not seem to be the case w/ 4.5.
You can reproduce this with the following steps.
From the command line:
dotnet --version
6.0.101
mkdir autowrapper-statuscode-issue
cd autowrapper-statuscode-issue/
dotnet new webapi
dotnet add package AutoWrapper.Core --version 5.0.0-rc-03
Please note that, while this is the minimal set of steps to reproduce the issue, in my larger and more complex project, where both ASP.NET Core MVC and API are hosted in a single project, removing the [Produces] attribute is not enough to work around the issue. The result is still being encoded as JSON by (some) middleware before it reaching AutoWrapper.
The text was updated successfully, but these errors were encountered:
nwoolls
changed the title
StatusCode() method broken by [Produces] attribute
StatusCode() method broken by [Produces] attribute (AutoWrapper 5.0)
May 10, 2022
I am trying to upgrade AutoWrapper from 4.5 to 5.0 in order to work around the problems reported in issue #133.
In doing so, I've found a problem that does not seem to exist in 4.5, and am hoping you can provide some advice.
The problem is that, when using the controller's
StatusCode()
method to return a status code, if the controller or action has the[Produces("application/json")]
attribute, the result is returned as astring
rather than anobject
. As seen in the details of issue #133, this does not seem to be the case w/ 4.5.You can reproduce this with the following steps.
From the command line:
dotnet --version 6.0.101 mkdir autowrapper-statuscode-issue cd autowrapper-statuscode-issue/ dotnet new webapi dotnet add package AutoWrapper.Core --version 5.0.0-rc-03
Edit
Program.cs
and add:Edit
WeatherForecastController.cs
and add:Run the project.
The following are examples where the result may either by an
object
or astring
:Example 1 - Returns a
string
"An error occurred - returning status code"
Example 2 - returns an
object
Please note that, while this is the minimal set of steps to reproduce the issue, in my larger and more complex project, where both ASP.NET Core MVC and API are hosted in a single project, removing the
[Produces]
attribute is not enough to work around the issue. The result is still being encoded as JSON by (some) middleware before it reaching AutoWrapper.The text was updated successfully, but these errors were encountered: