Skip to content

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

Merged
merged 1 commit into from
Jan 7, 2022
Merged

Conversation

layomia
Copy link
Contributor

@layomia layomia commented Jan 7, 2022

Makes delegates unsupported by JsonSerializer for both reflection & source-gen modes. If properties of these types are included for serialization, then NotSupportedException 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* and System.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.

@layomia layomia added this to the 7.0.0 milestone Jan 7, 2022
@layomia layomia requested a review from steveharter January 7, 2022 05:37
@layomia layomia self-assigned this Jan 7, 2022
@ghost
Copy link

ghost commented Jan 7, 2022

Tagging subscribers to this area: @dotnet/area-system-text-json
See info in area-owners.md if you want to be subscribed.

Issue Details

Makes delegates unsupported by JsonSerializer for both reflection & source-gen modes. If properties of these types are included for serialization, then NotSupportedException is thrown. Otherwise if the props are annotated with [JsonIgnore], then they are ignored at runtime as expected.

Fixes #62354. We avoid treating the System.Action* and System.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.

Author: layomia
Assignees: layomia
Labels:

area-System.Text.Json

Milestone: 7.0.0

@@ -23,6 +23,8 @@ public override bool CanConvert(Type type)
type == typeof(SerializationInfo) ||
type == typeof(IntPtr) ||
type == typeof(UIntPtr) ||
// Exlude delegates.
Copy link
Contributor

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

Copy link
Contributor Author

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.

@layomia layomia merged commit e0287b7 into dotnet:main Jan 7, 2022
@layomia
Copy link
Contributor Author

layomia commented Jan 7, 2022

/backport to release/6.0

@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2022

Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/1669025831

@ghost ghost locked as resolved and limited conversation to collaborators Feb 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

System.Text.Json source generator does not ignore delegate properties
3 participants