Bug 329 - Nullable<Date> and Nullable<Time> serialize incorrectly as DateTime
Summary: Nullable<Date> and Nullable<Time> serialize incorrectly as DateTime
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML ()
Version: master
Hardware: All All
: Normal major
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
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:

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
smaller console-based test case (1.21 KB, application/octet-stream)
2011-08-21 10:25 UTC, Sebastien Pouliot

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:

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:

	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">

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">
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

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!!!