Hi,
We are having some trouble serializing a WebDatePicker on a server and deserializing it on another one where Culture is different (or even if it is the same server but Culture used on deserialization depends on the web client).
Desrialization fails with "String was not recognized as a valid DateTime."
Is this the expected behavior?
Thanks.
Here is how you can reproduce this issue:
protected void Page_Load(object sender, EventArgs e)
{ if (!Page.IsPostBack) { PersistenceManager lManager = PersistenceManager.GetInstance(); MemoryStream lSTream = (MemoryStream)GetDatePicker(); lSTream.Position = 0; Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("es-UY"); PersistenceData lData = PersistenceData.FromStream(lSTream); var lControl = new WebDatePicker(); lManager.LoadControl(lControl, lData.Controls[0]); PlaceHolder1.Controls.Add(lControl);
} }
public Stream GetDatePicker(){ WebDatePicker lDatePicker = new WebDatePicker(); lDatePicker.BackColor = System.Drawing.Color.Red; lDatePicker.Value = new DateTime(2012, 12, 21);
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
PersistenceManager lManager = PersistenceManager.GetInstance(); PersistenceData lData = new PersistenceData(); lData.Controls.Add(lManager.SaveControl(lDatePicker, "control")); return lData.ToStream(); }
Hello Ricardo,This issue you are facing is not specific to our controls – it is general programming issue. You can find discussions regarding it on the following links:http://stackoverflow.com/questions/8182895/how-to-serialize-deserialize-a-double-value-independent-of-culture
http://stackoverflow.com/questions/4876198/what-is-the-right-approach-for-serializing-deserializing-data-in-a-culture-insen
http://stackoverflow.com/questions/3231386/when-should-i-specify-currentculture-or-invariantculture-and-when-should-i-leave
I am familiar with the issue but I do not have control over this serialization as I am doing it using Persistence Framework save and load functions.
Isn't Persistence Framework expected to work under this circumstances? The Date that is being serialized is that of the WebDatePicker.
I set to bold to the part of the code that uses PersistenceFramework in the previous post, just in case it wasn't clear enough.
Thanks