-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Throws an exception on a simple JSON structure return. #30938
Comments
If you believe this is not a cycle and instead you just have a very deep heirarchy, you can set |
@gammafour - can you share what your object graph looks like that you are trying to serialize? Do you have cycles in your object or is it that your graph actually really deep that you are going over the 1_000 max depth?
What settings/options do you use with |
I ran into a similar issue when deserializing a model with a one to many relationship for a Blazor based web app. To solve the issue we had to add JsonIgnore and a reference to System.Text.Json 4.7.0-preview2.19523.17
|
@timmyreilly Thanks for your suggestion. I had the same problem and JsonIgnore attribute worked for me. I could not find JSonSerializationOptions for reference loop handling in Core 3.0 |
@JAYARAJ2014 - the reference loop feature is WIP for 5.0, see: https://github.com/dotnet/corefx/issues/41002 |
Another workaround is to use
|
The preview version for
var options = new JsonSerializerOptions
{
ReferenceHandling = ReferenceHandling.Preserve
};
string json = JsonSerializer.Serialize(objectWithLoops, options); Here's the spec doc including samples and notes about many scenarios. |
@jozkee, I tried using the alpha from the dotnet5 gallery and it seems to be a prior build number (19523.8) that doesn't yet have the
|
@catfood make sure to select version |
@jozkee the highest version for System.Text.Json that I am seeing is only 4.7.0. I have the |
@GrangeLife You are probably using default package source gallery (nuget.org). Go to Package Manager Settings and add dotnet5 daily feed to your Package Sources and search there for version
|
@erkanKR, it seems that you are using a wrong version. Make sure to select |
The versioning schema of the packages on the nightly feed changed a bit. Since we went from |
I don't have time to figure out exactly what's buggy about the System.Text.JSON, but this code was working in .NET Core 2.2.
Now I get:
When I switch back to NewtonSoft, it works just like it did before the upgrade to .NET Core 3.0.
The text was updated successfully, but these errors were encountered: