-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Order of serialized properties determined by dictionary enumeration on fast-path source generators #59043
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsCurrently, the fast-path source generator will use the Note that dictionary enumeration does not provide any guarantees on ordering, as such it is likely that this could end up not honoring the desired serialization order (e.g. as specified by the
|
Given that the source generator targets |
I wonder whether when built in DEBUG we should have our dictionary randomize its enumeration. Long ago, before string hash codes were randomized by default, the libraries used to randomize string hashcodes (XOR them with the build number or similar) in DEBUG only. |
@danmoseley I have worked on a large application that relied on |
@GSPP in general no framework can reasonably guarantee undefined behavior, post v1 or not. It so heavily constrains maintenance, perf improvements, etc. As well we do not test such behavior - so we do not necessarily know when it changes - nor necessarily know that anyone depends on it. That may turn up much later when the product is in servicing mode. We have seen the result of this in .NET Framework where callers even depended on details of timing to the extent performance improvements caused breaks and had to be reverted later. .NET Core introduced SxS deployment to give more freedom to make improvements like this. There can always be exceptions where something is so widely assumed in the ecosystem that it is best to document it. I do not have the data to guess whether this is the case here or not but my guess is that it is unlikely. |
Moving to Future, as we won't have time to work on this in the .NET 7 timeframe. |
Fixed by #87383. |
Currently, the fast-path source generator will use the
TryFilterSerializableProps
method to determine the properties that are serializable. The results are returned as a dictionary, which the source generator will enumerate in order to emit the relevant logic.Note that dictionary enumeration does not provide any guarantees on ordering, as such it is likely that this could end up not honoring the desired serialization order (e.g. as specified by the
JsonPropertyOrderAttribute
). That being said, the current implementation of System.Collections.Generic.Dictionary happens to preserve ordering due to an implementation detail that may well change in the future. We should update theTryFilterSerializableProps
method to provide more robust guarantees on property ordering.The text was updated successfully, but these errors were encountered: