-
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
Should we remove DynamicallyAccessedMembers attributes on JsonSerializer? #52268
Comments
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsIn 5.0, we annotated the JsonSerializer APIs with Lines 43 to 44 in 300c39d
Lines 26 to 27 in 300c39d
In 6.0, we resolved all the ILLink warnings in System.Text.Json in #51886, which caused us to also add the Having both sets of attributes on these APIs isn't really ideal. The The small benefit it does provide is in the case where the user is not serializing a graph, but just a class with primitive properties. However, even in this case, we'd like the user to move to use the source generator instead. So keeping these attributes for this tiny case doesn't seem to outweigh the benefit of the encouragement to move to using the source generator. We also didn't annotate the DataContractSerializer and XmlSerializer APIs like this. We just marked the unsafe APIs with However, if we have plans for making the non-source generation Json serializer APIs work with trimming in 6.0, it might not be worth the effort of removing these attributes now, just to add them back in the near future. cc @vitek-karas @agocke @layomia @steveharter
|
I think we should remove them - as mentioned they are not enough and won't help in most cases anyway.
If we do come up with a solution, I doubt it will be using the exact same annotations, so we would have to change this anyway. I don't mind revisiting this code again, if we have a reason to do so. |
Just an FYI - we have trimming tests for these attributes: Lines 31 to 39 in c9c954b
I assume as part of this work, we would be deleting those tests as well. |
@steveharter @layomia - I plan on working on this. Just ensuring you don't have any objections to removing these attributes. |
* Remove DynamicallyAccessedMembers on JsonSerializer Fix #52268 * Remove DynamicallyAccessedMembers from System.Net.Http.Json These are no longer required since System.Text.Json doesn't have these annotations anymore. * Update PreviousNetCoreApp baseline for attribute removal * Fix trimming tests on browser-wasm * Fix Json tests on EnableAggressiveTrimming leg
Didn't we decide that if we had a special [DAM] we could propagate these from user code to preserve type the call sites? |
Yes, when the linker supports making a custom [DAM], then we can mark these methods with that. But we don’t have that feature yet. |
In 5.0, we annotated the JsonSerializer APIs with
DynamicallyAccessedMembers
attributes in #38595.runtime/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.String.cs
Lines 43 to 44 in 300c39d
runtime/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.String.cs
Lines 26 to 27 in 300c39d
In 6.0, we resolved all the ILLink warnings in System.Text.Json in #51886, which caused us to also add the
RequiresUnreferencedCode
attributes. This is because the trim annotations can't model everything that needs to be preserved to make these APIs trim compatible. For example, see dotnet/linker#1087.Having both sets of attributes on these APIs isn't really ideal. The
DynamicallyAccessedMembers
attributes will only preserve members on the top-level type. So having theDynamicallyAccessedMembers
gives a false sense of hope that this API will work with trimming, when in reality it won't.The small benefit it does provide is in the case where the user is not serializing a graph, but just a class with primitive properties. However, even in this case, we'd like the user to move to use the source generator instead. So keeping these attributes for this tiny case doesn't seem to outweigh the benefit of the encouragement to move to using the source generator.
We also didn't annotate the DataContractSerializer and XmlSerializer APIs like this. We just marked the unsafe APIs with
RequiresUnreferencedCode
.However, if we have plans for making the non-source generation Json serializer APIs work with trimming in 6.0, it might not be worth the effort of removing these attributes now, just to add them back in the near future.
cc @vitek-karas @agocke @layomia @steveharter
The text was updated successfully, but these errors were encountered: