Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialization throws InvalidCastException if POCO has added additional property after serialization. #180

Open
nsatyanarayana-conga opened this issue Jul 1, 2020 · 0 comments

Comments

@nsatyanarayana-conga
Copy link

nsatyanarayana-conga commented Jul 1, 2020

I am using Hyperion 0.9.15 and testing below scenario.

Created POCO object and did serialization and stored stream in file stream. Then I have added another new property and try to
de-serialize it where I am getting InvalidCastException. I tried with versiontolerance enabled and disabled having same issue.

Is this problem may be related to Hyperion or something i'm missing?. Guide me how to solve my issue if I am missing any configuration.
----------------------------POCO--------------------

    public class Employee
    {
        public string Name { get; set; }

        public double Salary { get; set; }

    }

------------------------Serialize to File---------------------------------

      public void FileSerialize()
        {
            var employee = new Employee
            {
                Name = "Foo",
                Salary = 2500.0
            };
            var fileName = @"C:\FromDDrive\words.txt";
            using FileStream fs = File.OpenWrite(fileName);

            _serializer.Serialize(employee, fs);
            Assert.NotNull(fs);
        }

-----------------------------Updated POCO----------------

 public class Employee
 {
        public string Name { get; set; }
        public double Salary { get; set; }
      public int Age { get; set; }
 }

-----------------De-serialize------------------------------------

public void FileSerializeRead()
        {

            var fileName = @"C:\FromDDrive\words.txt";
            using FileStream fs = File.OpenRead(fileName);

            //_serializer.Serialize(employee, fs);
            //fs.Position = 0;
            var actual = _serializer.Deserialize<Employee>(fs);
            Assert.Equal(employee.Name, actual.Name);
            Assert.NotNull(fs);
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant