DateTime serialization bug

Oct 21, 2012 at 11:42 AM

Hi, following code demonstrates the bug:

namespace ConsoleApplication1
	using System;

	public class Program
		private static void Main(string[] args)
			var time = new DateTime(2012, 12, 31);
			var serializer = new YAXLib.YAXSerializer(typeof (DateTime));
			serializer.SerializeToFile(time, "time.xml");
			var newTime = (DateTime)serializer.DeserializeFromFile("time.xml");



Set your region to for example Finland (Finnish) to see the bug.

Here's my output:

31.12.2012 0:00:00
1.1.0001 0:00:00

Why not just use DateTime.ToString("o") format (see It would preserve much more information than the current format and it would not have these culture issues.

Oct 21, 2012 at 11:52 AM

I just realized I could use [YAXFormat("o")] attribute which fixes the problem.