-
Notifications
You must be signed in to change notification settings - Fork 9.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
Stack overflow. when serialize object to Json #13924
Comments
@ahsonkhan here's a minimal repro without MVC: https://github.com/pranavkm/repro/tree/prkrishn/json-stackoverflow. This stackoverflow seems to be resolved using your patched binary, although I do get a null ref: Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'text')
at System.Text.Json.JsonWriterHelper.NeedsEscaping(ReadOnlySpan`1 value, JavaScriptEncoder encoder)
at System.Text.Json.Utf8JsonWriter.WriteStringEscape(ReadOnlySpan`1 value)
at System.Text.Json.Utf8JsonWriter.WriteStringValue(ReadOnlySpan`1 value)
at System.Text.Json.Utf8JsonWriter.WriteStringValue(String value)
at System.Text.Json.Serialization.Converters.JsonConverterString.Write(Utf8JsonWriter writer, String value, JsonSerializerOptions options)
at System.Text.Json.JsonPropertyInfoNotNullable`4.OnWrite(WriteStackFrame& current, Utf8JsonWriter writer)
at System.Text.Json.JsonPropertyInfo.Write(WriteStack& state, Utf8JsonWriter writer)
at System.Text.Json.JsonSerializer.HandleObject(JsonPropertyInfo jsonPropertyInfo, JsonSerializerOptions options, Utf8JsonWriter writer, WriteStack& state)
at System.Text.Json.JsonSerializer.WriteObject(JsonSerializerOptions options, Utf8JsonWriter writer, WriteStack& state)
at System.Text.Json.JsonSerializer.Write(Utf8JsonWriter writer, Int32 originalWriterDepth, Int32 flushThreshold, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.JsonSerializer.WriteAsyncCore(Stream utf8Json, Object value, Type inputType, JsonSerializerOptions options, CancellationToken cancellationToken)
at ConsoleApp17.Program.Main(String[] args) in C:\Users\Pranav\source\repos\ConsoleApp17\ConsoleApp17\Program.cs:line 29
at ConsoleApp17.Program.<Main>(String[] args) Could you have a look? |
This issue has been fixed already (in dotnet/corefx#40997) and cannot be reproduced. The root cause was not guarding against null pointers up-front before calling the
Keep in mind, that isn't a null ref, but argument validation - ArgumentNullException. The patch I shared didn't have that fix at the time, and you'd see that behavior for empty strings in the object you are serializing ( |
Thanks for the report @liuguiyou. This issue will be resolved in 3.0 RTM. In the meanwhile, you could consider using Newtonsoft.Json based JSON formatters in your application: https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-2.2&tabs=visual-studio#jsonnet-support |
Describe the bug
When api serialize object to Json, stack overflow
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Not stack overflow
Screenshots
Code solution file
src.zip
The text was updated successfully, but these errors were encountered: