Bug 329 - Nullable<Date> and Nullable<Time> serialize incorrectly as DateTime
Summary: Nullable<Date> and Nullable<Time> serialize incorrectly as DateTime
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML ()
Version: master
Hardware: All All
: Normal major
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-08-18 23:27 UTC by Wei-Yuen Tan
Modified: 2012-01-03 19:47 UTC (History)
6 users (show)

Tags: monotouch
Is this bug a regression?: ---
Last known good build:


Attachments
Minimal code necessary to demonstrate problems serialization nullable date and nullable time (1.02 KB, application/zip)
2011-08-18 23:27 UTC, Wei-Yuen Tan
Details
smaller console-based test case (1.21 KB, application/octet-stream)
2011-08-21 10:25 UTC, Sebastien Pouliot
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Wei-Yuen Tan 2011-08-18 23:27:43 UTC
Created attachment 152 [details]
Minimal code necessary to demonstrate problems serialization nullable date and nullable time

Given the following serializable class:

	[System.SerializableAttribute()]
	public partial class doc
	{
		[System.Xml.Serialization.XmlElementAttribute("MyTime", DataType="time", IsNullable=false)]
		public System.DateTime MyTime;

		[System.Xml.Serialization.XmlElementAttribute("MyTimeNullable", DataType="time", IsNullable=true)]
		public System.Nullable<System.DateTime> MyTimeNullable;

		[System.Xml.Serialization.XmlElementAttribute("MyDate", DataType="date", IsNullable=false)]
		public System.DateTime MyDate;

		[System.Xml.Serialization.XmlElementAttribute("MyDateNullable", DataType="date", IsNullable=true)]
		public System.Nullable<System.DateTime> MyDateNullable;
	}

MyTime and MyTimeNullable should serialize to exactly the same string value if neither are null.  Same for MyDate and MyDateNullable.

Unfortunately, I get the following output:

<?xml version="1.0" encoding="utf-16"?>
<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <MyTime>20:13:33.150455</MyTime>
  <MyTimeNullable>2011-08-18T20:13:33.150455-07:00</MyTimeNullable>
  <MyDate>2011-08-18</MyDate>
  <MyDateNullable>2011-08-18T20:13:33.150455-07:00</MyDateNullable>
</doc>

It appears that the MonoTouch runtime is serializing nullable date/time in dateTime format.  

This is not acceptable, and on the critical path preventing my product from being shipped.

This is with the latest stable release as of today, i.e. Mono Framework 2.10.4, and MonoTouch 4.0.5.

Source code is attached which will demonstrate this problem.
Comment 1 Sebastien Pouliot 2011-08-21 10:24:28 UTC
This bug is inherited from the Mono BCL and exists on 2.10.4 and 'master'. On MS .NET is does return the following:

<?xml version="1.0" encoding="utf-16"?>
<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <MyTime>10:17:08.0919765-04:00</MyTime>
  <MyTimeNullable>10:17:08.0919765-04:00</MyTimeNullable>
  <MyDate>2011-08-21</MyDate>
  <MyDateNullable>2011-08-21</MyDateNullable>
</doc>
Comment 2 Sebastien Pouliot 2011-08-21 10:25:18 UTC
Created attachment 160 [details]
smaller console-based test case
Comment 3 Wei-Yuen Tan 2011-09-19 19:21:21 UTC
any progress?
Comment 4 Wei-Yuen Tan 2011-10-23 19:37:30 UTC
still hoping for some movement on this.  I would love to debug it myself but am not savvy enough to do so.
Comment 5 Miguel de Icaza [MSFT] 2012-01-03 15:41:50 UTC
Reseting the priority, it is not a regression, so it can not be a blocker.
Comment 6 Miguel de Icaza [MSFT] 2012-01-03 19:41:02 UTC
Fixed.

This will be available in the upcoming Mono, MonoTouch and Mono for Android releases.
Comment 7 Miguel de Icaza [MSFT] 2012-01-03 19:41:13 UTC
Forgot to close the bug
Comment 8 Wei-Yuen Tan 2012-01-03 19:47:02 UTC
orale guey...porfin!!!