Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have serialized the student object and have created the abc.dat file.
The file is

[Serializable]
public class Student
{
public string Name { get; set; }

public int ID { get; set; }

public string Address { get; set; }


}


Now i have modified he datatype of ID to string then when i am trying
to de-serailize the abc.dat file then i am getting the arguement exception.

Error found:
XML
A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll

[Serializable]
    public class Student
    {
        public string Name { get; set; }

        public <b><u></u>string</b> ID { get; set; }

        public string Address { get; set; }


    }

Thanks in advance
Posted

You cannot serialize an object to a file, modify the original class, and then expect the deserialization process will run fine.

You should think more carefully about making your ID of type string. What is the benefit you get for that?
 
Share this answer
 
Just delete current serialized file (with int in it). Going forward serialization/de-serialization will work (unless you change type again :) )
 
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