Answer the question
In order to leave comments, you need to log in
Error in XML deserialization?
I have an array of strings and another string - structure fields.
You need to save these fields to the file, but in such a way that the data looks convenient in the file in case of emergency.
Decided to serialize them through XML.
It serializes like normal, but deserialization fails - I get an error.
Error in XML file:
public static bool LoadTableFromPath(string path, out TableData tableData)
{
tableData = new TableData();
FileStream fs = null;
XmlSerializer formatter = new XmlSerializer(typeof(string[]));
try
{
fs = new FileStream(path, FileMode.Open, FileAccess.Read);
tableData.words = new string[100];
tableData.words = (string[])formatter.Deserialize(fs);
tableData.description = Convert.ToString(formatter.Deserialize(fs));
fs.Close();
}
catch (Exception exc)
{
Console.WriteLine(">>>" + exc.Message);
if (fs != null)
fs.Close();
PasswordAnalyserFront.state = PasswordAnalyserFront.ConnectState.Inner;
return false;
}
PasswordAnalyserFront.state = PasswordAnalyserFront.ConnectState.Inner;
return true;
}
public static void SaveTableFromPath(string path, TableData tableData)
{
using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write))
{
XmlSerializer formatter = new XmlSerializer(typeof(string[]));
formatter.Serialize(fs, tableData.words);
formatter = new XmlSerializer(typeof(string));
formatter.Serialize(fs, tableData.description);
}
}
Answer the question
In order to leave comments, you need to log in
What's the problem with creating a serialization class that includes both words and description?
hint: copy xml and in studio Edit-PasteSpecial
<?xml version="1.0" encoding="UTF8"?>
<FILE>
<WORDS>
<WORD>abcd</WORD>
<WORD>qwe</WORD>
<WORD>fdsa</WORD>
</WORDS>
<DESCRIPTION>this is description</DESCRIPTION>
</FILE>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question