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
{{ message }}
Repository navigation
Breaking change: ArgumentNullException thrown when null is passed as input type to some JsonSerializer serialize methods #21376
In .NET Core 3.1 and versions 4.6.0-4.7.2 of the System.Text.Json library, null could be passed as the type argument to various serialization methods on JsonSerializer, if the value to serialize was also null. In .NET 5/version 5.0.0, an ArgumentNullException is thrown if null is passed as the type argument.
Version introduced
.NET 5
Old behavior
In .NET Core 3.1 and versions 4.6.0-4.7.2 of the System.Text.Json library, null could be passed as the type argument to various serialization methods on JsonSerializer, if the value to serialize was also null.
New behavior
In .NET 5/version 5.0.0, an ArgumentNullException is thrown if null is passed as the type argument.
Reason for change
null is not expected as a valid input for the type arguments to the various serialization methods. The change was made to ensure correctness and prevent unexpected bugs.
Recommended action
Ensure that a non-nulltype argument is passed to applicable serialization methods on JsonSerializer. Strategies include handwriting null for values which are null and their type cannot be determined.
Activity
layomia commentedon Nov 7, 2020
cc @gewarren, @tdykstra
layomia commentedon Nov 9, 2020
Looks like this was filed in #20823.