Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi i have an application in which i save my data, save it to the database and then fetch the data whenever i need it, something like save and restore
i have list<> of objects (class) and serialize them to binary data then deserialize it for restoring,i can see that the data saved and restored as well, but when i run my program there is an error that i really don`t understand where it came from , if i run my application without save and restore , it will run without error but after restoring the same data the program will interrupt with an error, the details of my class and the error are explained below.

class i think related to the error :

XML
[Serializable]
   class prof:faculty
   {

       public prof(string n, int ID, string f, string d, int did) : base(f,d,did)
        { nprof++; id = ID; name = n; }

       public prof(string n, int ID,faculty f, department d)
           : base(f,d)
       {
           nprof++; id = ID; name = n;
       }

       public prof(prof p, faculty f, department d)
           : base(f,d)
       {id=p.FId; name = p.FName; }


       public int PId { get { return id; } set { id = value; } }
       public string PName { get { return name; } set { name = value; } }
       public static int Nprof { get { return nprof; } }
       public void addcourse(course c) { teaching.Add(c); }
       public List<course> Teaching { get { return teaching; } }

       public void addtime(int d, int[] s) { teachingprog.Add(d,s); }
       public Dictionary<int, int[]> Teachingprog { get { return teachingprog; } }



       private string name;
       private int id;
       public Dictionary<int, int[]> teachingprog = new Dictionary<int, int[]>();
       private List<course> teaching = new List<course>();


       static int nprof = 0;
   }



error:


C#
foreach (course cc in p.Teaching)
                           for (int j = 0; j < Nroom; j++)
                           {
                               int ii = Courses.IndexOf(cc);



this is the error part, int ii valued with -1(makes its following computation wrong) which if i am not wrong means cc could not be found in courses list<>

but why?
i serialize the prof list<> and the courses<> list
no error before save and restore, but after restore there is a error
Posted
Updated 18-Dec-14 22:05pm
v3
Comments
Maciej Los 18-Dec-14 16:28pm    
Not enough information...
To be able to help you, we need to know how do you serialize/deserialize data. This part of code does telling us nothing.

1 solution

Please, read my comment to the question. That makes that direct answer is impossible.

I'd suggest to read these:
Serialization (C# and VB)[^]
XML Serialization and Deserialization: Part-1[^]
XML Serialization and Deserialization: Part-2[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900