Skip to content

System.Xml.Serialization.XmlSerializer does silently ignore System.DatetimeOffset values #1406

Closed

Description

@Bonuspunkt

example code

public class DatetTimeOffsetContainer
{
    public DateTimeOffset DateTimeOffset { get; set; }
}

public void Test()
{
    var serializer = new XmlSerializer(typeof(DatetTimeOffsetContainer));

    var expected = new DatetTimeOffsetContainer
    {
        DateTimeOffset = new DateTimeOffset(2018, 1, 1, 0, 0, 0, TimeSpan.Zero)
    };

    var stream = new MemoryStream();
    serializer.Serialize(stream, expected);

    stream.Position = 0;

    var actual = (DatetTimeOffsetContainer) serializer.Deserialize(stream);

    Debug.Assert(expected.DateTimeOffset == actual.DateTimeOffset);
    // actual.DateTimeOffset == default(DateTimeOffset)
}

stream content

<?xml version="1.0"?>
<DatetTimeOffsetContainer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <DateTimeOffset />
</DatetTimeOffsetContainer>

expected behavior: data does not disappear

Activity

  1. changed the title [-]'System.Xml.Serialization.XmlSerializer` does silently ignore `System.DatetimeOffset` values[/-] [+]`System.Xml.Serialization.XmlSerializer` does silently ignore `System.DatetimeOffset` values[/+] on Aug 12, 2018
  2. huanwu commented on Sep 13, 2018

    @huanwu
    Contributor

    @yujayee Could you see if it repro on full framework?

  3. jiayi11 commented on Sep 19, 2018

    @jiayi11
    Member

    It can repro on full framework, the DateTimeOffset value is silently ignored.

  4. drewfreyling commented on Apr 17, 2019

    @drewfreyling

    This sounds like a pretty major bug, I'm astounded it was marked as "Future"

  5. aarondglover commented on Apr 25, 2019

    @aarondglover

    Just hit this bug tonight.

    Serializing a ValueTuple which contains a DateTimeOffset and it is silently ignored!

  6. removed their assignment
    on May 28, 2019
  7. StephenBonikowsky commented on Jul 24, 2019

    @StephenBonikowsky
    Contributor

    There is a workaround for this problem, see the full discussion on stackoverflow ...

    [XmlElement("lastUpdatedTime")]
    public string lastUpdatedTimeForXml // format: 2011-11-11T15:05:46.4733406+01:00
    {
       get { return lastUpdatedTime.ToString("o"); } // o = yyyy-MM-ddTHH:mm:ss.fffffffzzz
       set { lastUpdatedTime = DateTimeOffset.Parse(value); } 
    }
    [XmlIgnore] 
    public DateTimeOffset lastUpdatedTime;
    

    This is definitely a bug we would like to fix, the fact that it also exists on the full framework complicates matters a bit since it is now much more difficulty to get bug fixes approved for full framework post 4.8. (See Scott's blog)

    The "Future" milestone simply means we can't consider it for the current 3.0 release.

  8. StephenBonikowsky commented on Aug 16, 2019

    @StephenBonikowsky
    Contributor

    Moving into next release (5.0)

  9. drewfreyling commented on Aug 16, 2019

    @drewfreyling

    Is there any chance of just fixing it in core and not framework for now?

  10. StephenBonikowsky commented on Aug 17, 2019

    @StephenBonikowsky
    Contributor

    The fix will be done in Core for sure, it's too late to get into the 3.0 release so for now it is going into our next big planned release which is 5.0.

    It could possibly go into a 3.0 servicing release but we don't know yet if that is possible since 3.0 is not yet out the door.

  11. added
    untriaged
    on Jan 7, 2020
  12. added this to the 5.0 milestone on Jan 7, 2020
  13. added and removed
    untriaged
    on Jan 7, 2020
  14. drewfreyling commented on Feb 4, 2020

    @drewfreyling

    @StephenBonikowsky now that 3.0 is out the door, what is the likelihood of it being fixed in a servicing release?

  15. StephenBonikowsky commented on Feb 4, 2020

    @StephenBonikowsky
    Contributor

    @drewfreyling Because it has a workaround we are targeting this for one of the upcoming 5.0 preview releases. So it won't be fixed in the servicing branch.

  16. added
    untriaged
    on Feb 23, 2020
  17. removed
    untriaged
    on Feb 24, 2020
  18. modified the milestones: 5.0.0, 6.0.0 on Jul 15, 2020
  19. ghost added
    in-pr
    on Jul 2, 2021
  20. ghost removed
    in-pr
    on Jul 15, 2021
  21. ghost locked as resolved and limited conversation to collaborators on Aug 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions