-
Notifications
You must be signed in to change notification settings - Fork 10k
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
ReferenceHandler.Preserve not working with ASP.NET Core 3.1 #28286
Comments
I wasn't able to repro this on ASP.NET 5.0, I suspect this is the same issue as dotnet/runtime#30445, where ASP.NET was missing out new properties on JsonSerializerOptions. @pranavkm do you know if there is a way to workaround this on ASP.NET 3.1? |
@jozkee should this issue be transferred to dotnet/aspnetcore? |
@layomia yup, I think they can give better guidance on this; transferring... |
You could register an instance of the formatter that is configured correctly: services.AddControllers(options =>
{
options.OutputFormatters.RemoveType<SystemTextJsonOutputFormatter>();
options.OutputFormatters.Add(new SystemTextJsonOutputFormatter(new JsonSerializerOptions(JsonSerializerDefaults.Web)
{
ReferenceHandler = ReferenceHandler.Preserve,
});
}); |
This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes. See our Issue Management Policies for more information. |
Can you also provide the solution for implementing this in a Blazor WebAssembly application? I tried using the following in the ConfigureServices function of my Server application but I'm still getting the JsonException... services.AddControllersWithViews().AddJsonOptions(options => |
I also tried the solution commented by pranavkm as shown below but then i just get a different error. Is this suppose to be the solution for Blazor WebAssembly as well? services.AddControllersWithViews(options => |
Thank you problem solved ;) |
Description
We have updated our ASP.NET Core 3.1 project to use System.Text.Json 5 in order to use the new ReferenceHandler.Preserve. Unfortunately this seems to have no effect. We are getting the following error message when we return an object with circular references:
Configuration
.NET Core SDK (reflecting any global.json):
Version: 3.1.404
Commit: 470f6754b3
Windows 10
x64
No, I don't know.
n/a
Other information
Configuration in Startup:
The text was updated successfully, but these errors were encountered: