I used the following codes to serialize an object of a custom class (which also has some members that are also custom classes):
MyType engine = new MyType(...);
using (FileStream fs = new FileStream(filename, FileMode.Create))
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fs, engine);
}
After running the code, I am getting a file which doesnt seem to have the right contents to capture the object:
:Lib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Also, when I deserialized the object, i am getting an error:
End of Stream encountered before parsing was completed.
After I added to all related custom classes the attribute [Serializable]. The output file looks more like correct now in that it has detailed data of the object in the file. But then I am getting another different error when I deserialized:
Unable to find assembly 'Lib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Any advice a appreciated.
This seems to work:
output: