Skip to content

Commit cc94f55

Browse files
authored
Apply suggestions from code review
1 parent 36f6a86 commit cc94f55

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

docs/core/compatibility/serialization/10.0/xmlserializer-obsolete-properties.md

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ title: "Breaking change: XmlSerializer no longer ignores properties marked with
33
description: "Learn about the breaking change in .NET 10 where properties marked with ObsoleteAttribute are now serialized by XmlSerializer instead of being ignored."
44
ms.date: 10/21/2025
55
ai-usage: ai-assisted
6-
ms.custom: https://github.com/dotnet/runtime/issues/100453
6+
ms.custom: https://github.com/dotnet/docs/issues/49054
77
---
88
# XmlSerializer no longer ignores properties marked with ObsoleteAttribute
99

10-
Starting in .NET 10, the behavior of <xref:System.Xml.Serialization.XmlSerializer> has 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.
10+
Starting in .NET 10, the behavior of <xref:System.Xml.Serialization.XmlSerializer> has changed with respect to how it handles properties marked with the <xref:System.ObsoleteAttribute> 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.
1111

12-
With this change, properties marked with `[Obsolete]` are now serialized by default unless the `IsError` property of the `[Obsolete]` attribute is set to `true`. If `IsError` is `true`, the serializer throws an <xref:System.InvalidOperationException> during creation. Additionally, an AppContext switch, `Switch.System.Xml.IgnoreObsoleteMembers`, has been introduced to allow developers to revert to the previous behavior if necessary.
12+
With this change, properties marked with `[Obsolete]` are now serialized by default unless the <xref:System.ObsoleteAttribute.IsError> property is set to `true`. If `IsError` is `true`, the serializer throws an <xref:System.InvalidOperationException> during creation. Additionally, an AppContext switch, `Switch.System.Xml.IgnoreObsoleteMembers`, has been introduced to allow developers to revert to the previous behavior, if necessary.
1313

1414
## Version introduced
1515

@@ -50,14 +50,10 @@ Console.WriteLine(writer.ToString());
5050

5151
Starting in .NET 10, properties marked with `[Obsolete]` are no longer excluded from XML serialization by default. Instead:
5252

53-
1. If the `[Obsolete]` attribute is applied with `IsError = false` (default), the property is serialized normally.
54-
2. If the `[Obsolete]` attribute is applied with `IsError = true`, the <xref:System.Xml.Serialization.XmlSerializer> throws an <xref:System.InvalidOperationException> during serializer creation.
53+
- If the `[Obsolete]` attribute is applied with `IsError = false` (default), the property is serialized normally.
54+
- If the `[Obsolete]` attribute is applied with `IsError = true`, the <xref:System.Xml.Serialization.XmlSerializer> throws an <xref:System.InvalidOperationException> during serializer creation.
5555

56-
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.
57-
58-
Using the same code as above, the output after the change is:
59-
60-
**Output after the change (default behavior):**
56+
Using the same code as shown in the previous behavior section, the output after the change is:
6157

6258
```xml
6359
<Example>
@@ -93,7 +89,7 @@ System.InvalidOperationException: Cannot serialize member 'ObsoleteProperty' bec
9389
```
9490

9591
> [!NOTE]
96-
> Properties that are marked as Obsolete have always successfully deserialized when data is present in the XML. While this change allows `[Obsolete]` properties to "round trip" from object to XML and back to object, the new behavior only affects the serialization half (object to XML) of the "round trip."
92+
> Properties that are marked as `[Obsolete]` have always successfully deserialized when data is present in the XML. While this change allows `[Obsolete]` properties to "round trip" from object to XML and back to object, the new behavior affects only the serialization half (object to XML) of the "round trip."
9793
9894
## Type of breaking change
9995

@@ -116,8 +112,3 @@ If any properties are marked with `[Obsolete(IsError = true)]` and are being ser
116112
## Affected APIs
117113

118114
- <xref:System.Xml.Serialization.XmlSerializer?displayProperty=fullName>
119-
120-
## See also
121-
122-
- [Pull Request dotnet/runtime#119865](https://github.com/dotnet/runtime/pull/119865)
123-
- [Related Issue dotnet/runtime#100453](https://github.com/dotnet/runtime/issues/100453)

0 commit comments

Comments
 (0)