-
Notifications
You must be signed in to change notification settings - Fork 5k
Make delegates unsupported by JsonSerializer #63495
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
Conversation
Tagging subscribers to this area: @dotnet/area-system-text-json Issue DetailsMakes delegates unsupported by Fixes #62354. We avoid treating the Candidate for 6.0.x backport.
|
....Json/src/System/Text/Json/Serialization/Converters/Value/UnsupportedTypeConverterFactory.cs
Show resolved
Hide resolved
@@ -23,6 +23,8 @@ public override bool CanConvert(Type type) | |||
type == typeof(SerializationInfo) || | |||
type == typeof(IntPtr) || | |||
type == typeof(UIntPtr) || | |||
// Exlude delegates. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: The "Exlude delegates" comment doesn't seem useful. If we keep it, there's also a typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I really just wanted some visual separation from the previous set of types. Will clean up in main/7.0+ in follow up PR.
/backport to release/6.0 |
Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/1669025831 |
Makes delegates unsupported by
JsonSerializer
for both reflection & source-gen modes. If properties of these types are included for serialization, thenNotSupportedException
is thrown. Otherwise if the props are annotated with[JsonIgnore]
, then they are ignored at runtime as expected. Note that this is not a breaking change since we already throw exceptions when these types are encountered during (de)serialization.Fixes #62354. We avoid treating the
System.Action*
andSystem.Func*
types as objects to be deserialized with parameterized ctors and generating invalid C# code that tries to invoke their ctors.Candidate for 6.0.x backport.