Below is an example of Datacontract deserialization of an object
public static void ReadObject(ClassTest tstObj)
{
FileStream fs = new FileStream(@"D:\" + tstObj.Name + ".xml", FileMode.Open);
XmlDictionaryReader reader =
XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas());
DataContractSerializer ser = new DataContractSerializer(typeof(ClassTest ));
// Deserialize the data and read it from the instance.
ClassTest deserializedTest =
(ClassTest )ser.ReadObject(reader, true);
reader.Close();
fs.Close();
}
To overcome the error just change the highlighted line to below:
XmlDictionaryReaderQuotas dictQuota = new XmlDictionaryReaderQuotas();
dictQuota.MaxNameTableCharCount = int.MaxValue;
dictQuota.MaxArrayLength = int.MaxValue;
dictQuota.MaxStringContentLength = int.MaxValue;
XmlDictionaryReader reader =
XmlDictionaryReader.CreateTextReader(writer, dictQuota);
public static void ReadObject(ClassTest tstObj)
{
FileStream fs = new FileStream(@"D:\" + tstObj.Name + ".xml", FileMode.Open);
XmlDictionaryReader reader =
XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas());
DataContractSerializer ser = new DataContractSerializer(typeof(ClassTest ));
// Deserialize the data and read it from the instance.
ClassTest deserializedTest =
(ClassTest )ser.ReadObject(reader, true);
reader.Close();
fs.Close();
}
To overcome the error just change the highlighted line to below:
XmlDictionaryReaderQuotas dictQuota = new XmlDictionaryReaderQuotas();
dictQuota.MaxNameTableCharCount = int.MaxValue;
dictQuota.MaxArrayLength = int.MaxValue;
dictQuota.MaxStringContentLength = int.MaxValue;
XmlDictionaryReader reader =
XmlDictionaryReader.CreateTextReader(writer, dictQuota);
No comments:
Post a Comment