Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Bonuspunkt opened this issue Aug 12, 2018 · 10 comments · Fixed by #55101
Closed

Comments

@Bonuspunkt
Copy link
Contributor

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

@Bonuspunkt Bonuspunkt changed the title 'System.Xml.Serialization.XmlSerializer does silently ignore System.DatetimeOffset` values System.Xml.Serialization.XmlSerializer does silently ignore System.DatetimeOffset values Aug 12, 2018
@huanwu
Copy link
Contributor

huanwu commented Sep 13, 2018

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

@jiayi11
Copy link
Member

jiayi11 commented Sep 19, 2018

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

@drewfreyling
Copy link

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

@aarondglover
Copy link

Just hit this bug tonight.

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

@jiayi11 jiayi11 removed their assignment May 28, 2019
@StephenBonikowsky
Copy link
Member

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.

@StephenBonikowsky
Copy link
Member

Moving into next release (5.0)

@drewfreyling
Copy link

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

@StephenBonikowsky
Copy link
Member

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.

@StephenBonikowsky StephenBonikowsky transferred this issue from dotnet/corefx Jan 7, 2020
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-Serialization untriaged New issue has not been triaged by the area owner labels Jan 7, 2020
@StephenBonikowsky StephenBonikowsky added this to the 5.0 milestone Jan 7, 2020
@StephenBonikowsky StephenBonikowsky added bug and removed untriaged New issue has not been triaged by the area owner labels Jan 7, 2020
@drewfreyling
Copy link

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

@StephenBonikowsky
Copy link
Member

@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.

@maryamariyan maryamariyan added the untriaged New issue has not been triaged by the area owner label Feb 23, 2020
@StephenBonikowsky StephenBonikowsky removed the untriaged New issue has not been triaged by the area owner label Feb 24, 2020
@HongGit HongGit modified the milestones: 5.0.0, 6.0.0 Jul 15, 2020
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jul 2, 2021
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jul 15, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Aug 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants