Skip to content

Conversation

@Lanayx
Copy link
Contributor

@Lanayx Lanayx commented Jan 12, 2026

This is related to my previous pull request #573, after testing I've figured out that DateType attribute fails for new types, for example:

using System.Xml.Serialization;

// DTO with DateTime field
public class PersonDto
{
    public int Id { get; set; }
    public string Name { get; set; } = string.Empty;
    [XmlElement("BirthDate", DataType="date")]
    public DateOnly BirthDate { get; set; }
}

class Program
{
    static void Main()
    {
        // Create a sample DTO
        var person = new PersonDto
        {
            Id = 1,
            Name = "John Doe",
            BirthDate = new DateOnly(1990, 5, 15)
        };

        // Serialize to XML
        var serializer = new XmlSerializer(typeof(PersonDto));

        using var stringWriter = new StringWriter();
        serializer.Serialize(stringWriter, person);
        string xml = stringWriter.ToString();

        Console.WriteLine("Serialized XML:");
        Console.WriteLine(xml);
        Console.WriteLine();

        // Deserialize back from XML
        using var stringReader = new StringReader(xml);
        var deserializedPerson = (PersonDto?)serializer.Deserialize(stringReader);

        if (deserializedPerson != null)
        {
            Console.WriteLine("Deserialized DTO:");
            Console.WriteLine($"Id: {deserializedPerson.Id}");
            Console.WriteLine($"Name: {deserializedPerson.Name}");
            Console.WriteLine($"BirthDate: {deserializedPerson.BirthDate:yyyy-MM-dd}");
        }
    }
}

This code fails with error Value 'date' cannot be used for the XmlElementAttribute.DataType property. The datatype 'http://www.w3.org/2001/XMLSchema:date' is missing
In this PR I've disallowed DataType for DateOnly and TimeOnly types.

@codecov
Copy link

codecov bot commented Jan 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.23%. Comparing base (4160214) to head (d22a300).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #579   +/-   ##
=======================================
  Coverage   94.23%   94.23%           
=======================================
  Files          32       32           
  Lines        3331     3331           
  Branches      526      526           
=======================================
  Hits         3139     3139           
  Misses        123      123           
  Partials       69       69           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mganss mganss merged commit 4f526b8 into mganss:master Jan 13, 2026
3 checks passed
@mganss
Copy link
Owner

mganss commented Jan 13, 2026

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants