Serialization exception using C# -
i new c# , trying write information file. got program running when have car class in same .cs file, when remove class .cs file in project, runtime error of
"serializationexception unhandled: objectmanager found invalid number of fixups. indicates problem in formatter".
below code car class included. when move class own car.cs file error starts getting thrown.
namespace consoleapplication2 { class program { [serializable()] public class car { public string make { get; set; } public string model { get; set; } public int year { get; set; } public car(string make, string model, int year) { make = make; model = model; year = year; } } /// <summary> /// deserializes list of cars , returns list user /// </summary> /// <returns>returns deserialized car list</returns> public list<car> readlist() { //create local list hold data list<car> carlist = new list<car>(); try { using (stream stream = file.open("data.bin", filemode.open)) { binaryformatter bin = new binaryformatter(); //point carlist deserialized stream carlist = (list<car>)bin.deserialize(stream); } } catch (ioexception) { } return carlist; }
when data.bin first created class type stored along data. if change class's namespace, formatter not able find class stored.
Comments
Post a Comment