Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 1, 2025

When serializing string[] properties with [XmlText] attribute, array elements were being concatenated without spaces, and deserialization was treating the entire content as a single element instead of splitting on whitespace as required by XML Schema list datatype specifications.

Problem

public class TestClass
{
    [XmlText]
    public string[] Items { get; set; }
}

var original = new TestClass { Items = new[] { "a", "b", "c", "d" } };
// Serialization produced: "abcd" (concatenated, no spaces)
// Deserialization produced: ["abcd"] (single element)

Expected Behavior

According to XML Schema list datatypes, elements should be space-separated:

// Serialization should produce: "a b c d" (space-separated)
// Deserialization should produce: ["a", "b", "c", "d"] (individual elements)

Solution

Serialization fix: Modified ReflectionXmlSerializationWriter.WriteText() to detect string[] arrays and join them with spaces using string.Join(" ", stringArray) before writing the text content.

Deserialization fix: Modified ReflectionXmlSerializationReader.WriteMemberText() to detect string[] arrays and split space-separated text using textValue.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries).

Test update: Updated the existing XML_TypeWithXmlTextAttributeOnArray() test to expect the correct behavior where ["val1", "val2"] serializes as "val1 val2" and deserializes back to ["val1", "val2"].

The changes are minimal and surgical, affecting only the specific case of string[] properties with [XmlText] attribute, ensuring existing functionality remains unchanged.

Fixes #115837.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] XML serialization of xs:list elements doesn't respect white-space separation Fix XML serialization of xs:list elements to respect white-space separation Aug 1, 2025
Copilot AI requested a review from StephenMolloy August 1, 2025 08:11
Copilot finished work on behalf of StephenMolloy August 1, 2025 08:11
@dotnet-policy-service
Copy link
Contributor

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

@jkotas jkotas deleted the copilot/fix-115837 branch August 31, 2025 22:52
@github-actions github-actions bot locked and limited conversation to collaborators Oct 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XML serialization of xs:list elements doesn't respect white-space separation

2 participants