-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Add breaking change documentation for XmlSerializer ObsoleteAttribute behavior in .NET 10 #49390
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
Add breaking change documentation for XmlSerializer ObsoleteAttribute behavior in .NET 10 #49390
Conversation
Co-authored-by: gewarren <[email protected]>
docs/core/compatibility/serialization/10.0/xmlserializer-obsolete-properties.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/serialization/10.0/xmlserializer-obsolete-properties.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/serialization/10.0/xmlserializer-obsolete-properties.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/serialization/10.0/xmlserializer-obsolete-properties.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/serialization/10.0/xmlserializer-obsolete-properties.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/serialization/10.0/xmlserializer-obsolete-properties.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/serialization/10.0/xmlserializer-obsolete-properties.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/serialization/10.0/xmlserializer-obsolete-properties.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/serialization/10.0/xmlserializer-obsolete-properties.md
Outdated
Show resolved
Hide resolved
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.
Pull Request Overview
This PR documents a breaking change in .NET 10 where XmlSerializer now serializes properties marked with [Obsolete] instead of treating them as if they were marked with [XmlIgnore]. The change includes an AppContext switch for backward compatibility and proper handling of IsError = true cases.
Key changes:
- New breaking change documentation with comprehensive examples and migration guidance
- AppContext switch documentation for restoring legacy behavior
- Updated TOC and overview page to include the new Serialization section
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
docs/core/compatibility/serialization/10.0/xmlserializer-obsolete-properties.md |
New breaking change article documenting XmlSerializer behavior change with code examples and migration paths |
docs/core/compatibility/toc.yml |
Added new Serialization section under .NET 10 breaking changes |
docs/core/compatibility/10.0.md |
Added Serialization section to the .NET 10 breaking changes overview |
docs/core/compatibility/serialization/10/xmlserializer-obsolete-properties.md
Show resolved
Hide resolved
docs/core/compatibility/serialization/10/xmlserializer-obsolete-properties.md
Show resolved
Hide resolved
docs/core/compatibility/serialization/10/xmlserializer-obsolete-properties.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/serialization/10/xmlserializer-obsolete-properties.md
Outdated
Show resolved
Hide resolved
Co-authored-by: gewarren <[email protected]>
Summary
Created comprehensive breaking change documentation for the .NET 10 change where XmlSerializer no longer ignores properties marked with ObsoleteAttribute. The document includes:
All code review suggestions have been applied, including renaming the directory from "serialization/10.0" to "serialization/10" to match the pattern used in other .NET 10 breaking change categories.
Original prompt
This section details on the original issue you should resolve
<issue_title>[Breaking change]: Fix ObsoleteAttribute incorrectly causing XML serialization to ignore properties with AppContext switch and SR resources</issue_title>
<issue_description>### Description
Starting in .NET 10, the behavior of the
System.Xml.Serialization.XmlSerializerhas changed with respect to how it handles properties marked with the[Obsolete]attribute. Previously, properties marked with[Obsolete]were treated as if they were also marked with[XmlIgnore], causing them to be excluded from XML serialization. This behavior was unintended and has been corrected.With this change, properties marked with
[Obsolete]will now be serialized by default unless theIsErrorproperty of the[Obsolete]attribute is set totrue. IfIsErroristrue, the serializer will throw anInvalidOperationExceptionduring creation. Additionally, an AppContext switch,Switch.System.Xml.IgnoreObsoleteMembers, has been introduced to allow developers to revert to the previous behavior if necessary.Version
.NET 10
Previous behavior
In previous versions of .NET, properties marked with the
[Obsolete]attribute were excluded from XML serialization, similar to properties marked with[XmlIgnore]. This behavior was unexpected and not aligned with the intended purpose of the[Obsolete]attribute, which is to provide compile-time warnings about deprecated APIs.Example
Output before the change:
New behavior
Starting in .NET 11, properties marked with
[Obsolete]are no longer excluded from XML serialization by default. Instead:[Obsolete]attribute is applied withIsError = false(default), the property will be serialized normally.[Obsolete]attribute is applied withIsError = true, theXmlSerializerwill throw anInvalidOperationExceptionduring serializer creation.An AppContext switch,
Switch.System.Xml.IgnoreObsoleteMembers, has been introduced to allow developers to restore the previous behavior where[Obsolete]properties are ignored during serialization. This switch is off by default.Example
Using the same code as above, the output after the change will be:
Output after the change (default behavior):
If the AppContext switch
Switch.System.Xml.IgnoreObsoleteMembersis enabled, the previous behavior is restored:Output with AppContext switch enabled:
If
[Obsolete(IsError = true)]is applied to a property, the following exception will be thrown during serializer creation:Type of breaking change
Reason for change
The previous behavior of treating
[Obsolete]as equivalent to[XmlIgnore]was unintended and inconsistent with the purpose of the[Obsolete]attribute. This change ensures that[Obsolete]is used solely for its intended purpose of providing compile-time warnings and does not affect runtime serialization behavior. The introduction of the AppContext switch allows developers to opt into the legacy behavior if necessary.Recommended action
Developers should review their codebases for any reliance on the previous behavior where
[Obsolete]properties were excluded from XML serialization. If this behavior is still desired, enable the AppContext switchSwitch.System.Xml.IgnoreObsoleteMembersas follows:If any properties are marked with
[Obsolete(IsError = true)]and are being serialized, update the code to either remove the[Obsolete]attribute or setIsError = falseto avoid runtime exceptions.Fixes #49054
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
Internal previews