Repository navigation
Fix XmlSerializer regression for derived XmlText properties - #130429
Merged
StephenMolloy merged 2 commits intoJul 15, 2026
Merged
StephenMolloy merged 2 commits into
StephenMolloy merged 2 commits into
Conversation
…ions] overrides on simpleContent base When a derived class re-declares [XmlText] (or [XmlNamespaceDeclarations]) on a virtual property override, InitializeStructMembers was incorrectly tracking those as new text/xmlns accessors for the derived mapping. When the base mapping has HasSimpleContent == true (only [XmlText], no elements), this caused SetContentModel to throw XmlIllegalSimpleContentExtension. Root cause: commit cc2019b changed the handling of base-declared members from 'continue' (skip entirely) to 'RemoveUniqueAccessor + fall-through'. This kept the derived member's element/attribute accessors correctly registered, but also let text and xmlns accessors be registered again, which the simpleContent check in SetContentModel rejects. Fix: introduce 'memberDeclaredByBase' and guard the text and xmlns accessor tracking with '&& !memberDeclaredByBase'. The derived member's accessors are still correctly registered via AddUniqueAccessor and added to mapping.Members (preserving cc2019b's intent for the reflection-based serializer); only the content-model-level tracking is suppressed for inherited overrides. Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a regression in System.Xml.Serialization where overriding a base-declared [XmlText] (and related [XmlNamespaceDeclarations]) member in a derived type could incorrectly re-register content-model accessors, leading to XmlIllegalSimpleContentExtension being thrown during type reflection.
Changes:
- Update
XmlReflectionImporter.InitializeStructMembersto detect members already declared by the base mapping and avoid re-tracking text/xmlns accessors for those members. - Add regression coverage for derived overrides of
[XmlText], plus additional tests around overriding[XmlAttribute]properties. - Add new shared test types to reproduce the inheritance/override scenarios.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/libraries/System.Runtime.Serialization.Xml/tests/SerializationTypes.RuntimeOnly.cs | Adds shared test types that model derived overrides of [XmlText] and [XmlAttribute] members. |
| src/libraries/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.RuntimeOnly.cs | Adds regression tests validating serialize/deserialize behavior for the new inheritance scenarios. |
| src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlReflectionImporter.cs | Fixes base-member override handling by suppressing duplicate text/xmlns content-model tracking. |
StephenMolloy
marked this pull request as ready for review
July 10, 2026 07:13
Contributor
Author
|
/ba-g wasm failures unrelated to this change |
This was referenced Jul 15, 2026
Contributor
|
Candidate for merging to NET10-release-branch ? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix XmlSerializer regression: derived [XmlText]/[XmlNamespaceDeclarations] overrides on simpleContent base
When a derived class re-declares [XmlText] (or [XmlNamespaceDeclarations]) on
a virtual property override, InitializeStructMembers was incorrectly tracking
those as new text/xmlns accessors for the derived mapping. When the base
mapping has HasSimpleContent == true (only [XmlText], no elements), this caused
SetContentModel to throw XmlIllegalSimpleContentExtension.
Root cause: commit cc2019b changed the handling of base-declared members
from 'continue' (skip entirely) to 'RemoveUniqueAccessor + fall-through'. This
kept the derived member's element/attribute accessors correctly registered, but
also let text and xmlns accessors be registered again, which the simpleContent
check in SetContentModel rejects.
Fix: introduce 'memberDeclaredByBase' and guard the text and xmlns accessor
tracking with '&& !memberDeclaredByBase'. The derived member's accessors are
still correctly registered via AddUniqueAccessor and added to mapping.Members
(preserving cc2019b's intent for the reflection-based serializer); only
the content-model-level tracking is suppressed for inherited overrides.
Co-authored-by: Copilot [email protected]
Fixes #121881