-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Custom IOutputFormatter not executed when using conventional routing #16969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Do you have an
Why not add a result filter that transforms |
Thanks for your time guys, greatly appreciated Yes the lack of
I.e. the formatters not being executed is by design? That troubles me a bit from an intuitive point of view.
I guess I could. But is this the intended way to deal with this? My concerns with this are:
Thanks again for your time 👍 |
Any update on this? |
Yes, formatters are only invoked when there are objects to serialize. There are plenty of action result types, including
You should use an |
Thank you for contacting us. Due to no activity on this issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue. |
Description
I'm using conventional routing: I'm programmatically assigning templates to controllers, ie not using
[ApiController][Route(" .. ")
but anIApplicationModelConvention
implementation. Also, I have a customIOutputFormatter
. The bug is that my custom formatter is not always executed: it depends on how my routing is configured. Below is my controller in which I use conventional routingWhen triggering the first and second actions my formatter is executed. For the last action my custom formatter is entirely skipped.
This behaviour is different when using attribute based routing. In this case, for all three actions below my custom outputter is executed:
This behaviour being different is unexpected and I believe it is a bug.
To Reproduce
Clone this repro repository. Run it and check out and hit the endpoints
All of them should return the same output but this is not the case.
Use-case
In case the reader is wondering why this is relevant: I'm working on a framework that implements json:api. We're using conventional routing because we want to programmatically configure routing for better extensibility and at the same time we want to use a custom formatter to add additional error details when an entity is not found.
The work-around for now is to return
NotFound(null)
instead ofNotFound()
.Further technical details
.NET Core SDK (reflecting any global.json): Version: 3.0.100 Commit: 04339c3a26 Runtime Environment: OS Name: Mac OS X OS Version: 10.14 OS Platform: Darwin RID: osx.10.14-x64 Base Path: /usr/local/share/dotnet/sdk/3.0.100/ Host (useful for support): Version: 3.0.0 Commit: 7d57652f33 .NET Core SDKs installed: 2.1.700 [/usr/local/share/dotnet/sdk] 2.2.301 [/usr/local/share/dotnet/sdk] 3.0.100 [/usr/local/share/dotnet/sdk] .NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
The text was updated successfully, but these errors were encountered: