anerjan / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

Deserializing custom arrays in V2 throws InvalidOperationException #168

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
email: eacuervo@gmail.com

What steps will reproduce the problem?

1. Trying to deserialize an array of a custom type using v2 (r364)
When trying to deserialize an array of a custom type I get the following error.

What is the expected output? What do you see instead?

Expected: To recreate what I serialized.
I see: An InvalidOperationException with the following message
"Type is not expected, and no contract can be inferred"

What version of the product are you using? On what operating system?

v2 (r364). I have tried this in both Full .NET 3.5 (Win7) as well as in CF 
(WinMo 6.5)

Please provide any additional information below.

Here is an example:

    [ProtoContract]
    public class Person {
        [ProtoMember(1)]
        public int Id {get;set;}
        [ProtoMember(2)]
        public string Name { get; set; }
        [ProtoMember(3)]
        public Address Address {get;set;}
    }
    [ProtoContract]
    public class Address {
        [ProtoMember(1)]
        public string Line1 {get;set;}
        [ProtoMember(2)]
        public string Line2 {get;set;}
    }

....

        private void button1_Click(object sender, EventArgs e)
        {
            Person[] people= new Person[20];
            for (int i = 0; i < enemies.Length; i++)
            {
                people[i] = new Person();
                people[i].Address = new Address();
                people[i].Address.Line1 = "1 A St";
                people[i].Address.Line2 = "Apt. B";
                people[i].Id = 1;
                people[i].Name = "Ed";
            }

            MemoryStream ms = new MemoryStream();

            Serializer.Serialize(ms, people);
            ms.Position = 0;
            Person[] people2 = Serializer.Deserialize<Person[]>(ms);

        }

Original issue reported on code.google.com by eacue...@gmail.com on 7 Apr 2011 at 7:18

GoogleCodeExporter commented 9 years ago

Original comment by marc.gravell on 13 Jun 2011 at 8:35

GoogleCodeExporter commented 9 years ago
Any update? I'm having the same issues. I've also tried to follow the below SO 
post. I'm using the latest beta version and Net30.

http://stackoverflow.com/questions/6093957/what-is-wrong-with-this-usage-of-a-pr
otobuf-net-surrogate

Original comment by sheetal5...@gmail.com on 1 Aug 2011 at 4:47

GoogleCodeExporter commented 9 years ago
This should be working fine. I've just checked it with the Person scenario in 
the issue and it works fine (IIRC this was fixed a significant time ago). If 
you can add a failing case, I'll look - but: cannot reproduce an error here. I 
need more information.

Original comment by marc.gravell on 2 Aug 2011 at 12:06