I'm building a program for my school's swim lesson organization, and I'm saving the data using XML serialization, but I keep getting an error every time I try to deserialize the data, it says "Runtime Error: Attempting to Deserialize an Empty Stream."
Here is my code to deserialize the file and put it into a window.
public StudentProfile()
{
InitializeComponent();
using (var file = File.Open(FindStudent.studentName + ".xml", FileMode.OpenOrCreate))
{
var bformatter = new BinaryFormatter();
var mp = (Person)bformatter.Deserialize(file);
file.Close();
nameBox.Text += mp.studentName;
parentBox.Text += mp.parentName;
yearBox.Text += mp.year;
semesterBox.Text += mp.semester;
sessionBox.Text += mp.session;
ageGroupBox.Text += mp.ageGroup;
sessionTimeBox.Text += mp.sessionTime;
levelBox.Text += mp.level;
paymentTypeBox.Text += mp.paymentType;
amountBox.Text += mp.amount;
checkNumberBox.Text += mp.checkNumber;
datePaidBox.Text += mp.datePaid;
}
}
I've tried some solutions on here, BinaryFormatter: SerializationException, but it still doesn't work. Can you guys help me?
Edit: I solved my error, using a different method, here is the code I ended up using to deserialize it. If anyone wants the serialization code, then I'll give it
Stream file = File.Open(@"C:\Swimmers\" + FindStudent.studentName + ".xml", FileMode.Open);
BinaryFormatter bformatter = new BinaryFormatter();
Person mp = (Person)bformatter.Deserialize(file);
file.Close();
nameBox.Text += mp.studentName;
parentBox.Text += mp.parentName;
yearBox.Text += mp.year;
semesterBox.Text += mp.semester;
sessionBox.Text += mp.session;
ageGroupBox.Text += mp.ageGroup;
sessionTimeBox.Text += mp.sessionTime;
levelBox.Text += mp.level;
paymentTypeBox.Text += mp.paymentType;
amountBox.Text += mp.amount;
checkNumberBox.Text += mp.checkNumber;
datePaidBox.Text += mp.datePaid;
}