G
Guest
Hi,
I have a simple class named DistributionSelections which stores two enums
and a dataset. I want to persist the object to a database for later
retrieval.
HERE IS THE CODE USED TO PERSIST THE OBJECT IN THE DB:
//====================================================
XmlSerializer x = new XmlSerializer(distributionselections.GetType());
StringWriter sw=new StringWriter(new StringBuilder());
x.Serialize(sw,distributionselections);
LogDB.LogEvent(sw.ToString());
//====================================================
This seems to work fine.
HERE IS THE CODE USED TO RECONSTITUTE THE OBJECT:
//====================================================
foreach(DataRow row in table.Rows)
{
XmlSerializer serializer = new XmlSerializer(typeof(DistributionSelections));
XmlTextReader xtr = new XmlTextReader( new
StringReader(row["Comment"].ToString()));
DistributionSelections selections=(DistributionSelections)
serializer.Deserialize(xtr);
//do something with the object.
}
//====================================================
When trying to reconstitue the object using the Deserialize method, I get an
error complaining that there is an unexpected tokey, the expected tokey is
'EndElement'.
I had expected object serialization/deserialization to be a bit easier. Am
I missing something?
Thank you very much for any help.
-Keith
I have a simple class named DistributionSelections which stores two enums
and a dataset. I want to persist the object to a database for later
retrieval.
HERE IS THE CODE USED TO PERSIST THE OBJECT IN THE DB:
//====================================================
XmlSerializer x = new XmlSerializer(distributionselections.GetType());
StringWriter sw=new StringWriter(new StringBuilder());
x.Serialize(sw,distributionselections);
LogDB.LogEvent(sw.ToString());
//====================================================
This seems to work fine.
HERE IS THE CODE USED TO RECONSTITUTE THE OBJECT:
//====================================================
foreach(DataRow row in table.Rows)
{
XmlSerializer serializer = new XmlSerializer(typeof(DistributionSelections));
XmlTextReader xtr = new XmlTextReader( new
StringReader(row["Comment"].ToString()));
DistributionSelections selections=(DistributionSelections)
serializer.Deserialize(xtr);
//do something with the object.
}
//====================================================
When trying to reconstitue the object using the Deserialize method, I get an
error complaining that there is an unexpected tokey, the expected tokey is
'EndElement'.
I had expected object serialization/deserialization to be a bit easier. Am
I missing something?
Thank you very much for any help.
-Keith