I have an SQL view with a field as such:
To_char(date, 'MM-DD-YYYY')
I have a C# object with a DateTime property. The objects are created based on data retrieved from the database being serialized and then being de-serialized into the object. All works well apart from the DateTime field. Depending on the format of the date returned from the DB, I either get an invalid XML error, or the date is set as 01-01-0001
Edit: Additional code as a response to comment.
De-serialize method:
public static object DeSerialize<T>(string data)
{
StringReader rdr = new StringReader(data);
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
var result = (T)xmlSerializer.Deserialize(rdr);
return result;
}
Class to be de-serialized:
public class VolumeData
{
public string name { get; set; }
public string study { get; set; }
public string group { get; set; }
public double volume { get; set; }
public DateTime date { get; set; }
}
Used as such:
List<VolumeData> volumeDataCollection = (List<VolumeData>)Serializer.DeSerialize<List<VolumeData>>(xmlData);
As I mentioned, I have no issue using these methods de-serializing other objects, or the properties within this class that is not a DateTime.
Thanks.