Ok, this one was a real pain in the ass. I would get this strange [Format_BadDateTime] error when trying to type in a Date in any of the DatePickers i would try to use. And only on Windows XP.
If i would use it outside the DataForm my binding would just get broken and that would basically be it!
On a different project, with similair setup i would get a [Arg_TargetInvocationException].
The problem occurs only if you’re using non-English localization settings on client computer (which means date formats other than MM/dd/yyyy) on Windows xp.
Well, i figured it out and it’s the Range attribute!
Range attribute is constituted pretyy awkard, ie for custom values it uses property type and string representations of minimum and maximum values. I think you can already see where’s the problem coming from:). Don’t know why it is different on WinXP or why it can’t figure it out there but basically what you need to do is keep it in the invariantCulture to avoid any problems:
((DateTime)someDate).ToString(CultureInfo.InvariantCulture)
where the end product would look something like this:
[Range(typeof(DateTime), @”01/01/1753 00:00:00″, @”01/01/9999 00:00:00″)]
And that’s it! Lost a good day on that crap, because my silverlight codegenerator used the local culture…
Oh, and i think that this problem is actually connected to my dev machine having different culture setup than english
marek Aug 23 , 2011 at 2:22 am /
Another way to solve this problem, is to set a CultureInfo of the current thread.
System.Threading.Thread.CurrentThread.CurrentCulture=System.Globalization.CultureInfo.InvariantCulture;