tonynhan / protobuf-net

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

Serializing Custom (inherited) lists #67

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
compy@uga.edu
==============

What steps will reproduce the problem?
1. Make a custom list class, IE:
[ProtoContract]
public class AddressCollection : List<string> { }
2. Simply serialize it using
AddressCollection ac = new AddressCollection();
ac.add("Test string");
ProtoBuf.Serializer.Serialize(stream, ac);

What is the expected output? What do you see instead?
I should see a nice handy stream with my byte data in it for the custom 
AddressCollection list.
Instead, I get an exception that "Known-type List 1 for 
ProtoIncludeAttribute must be a direct subclass of AddressCollection"

What version of the product are you using? On what operating system?
The latest Jul 16th release with VS2008 support

Please provide any additional information below.

Is it possible to serialize a custom list (class inherited from 
List<someobject>) above so long as "someobject" types can also be marked 
as a protocontract?

Original issue reported on code.google.com by compus...@gmail.com on 17 Aug 2009 at 4:23

GoogleCodeExporter commented 8 years ago
Could you try taking the [ProtoContract] off the list?

I would *hope* that this works, but I can't try it at this second - I've 
(literally) 
just re-installed my OS (to win7), so I'm not 100% up-and-running with "devenv" 
yet. 
Getting there...

Original comment by marc.gravell on 17 Aug 2009 at 5:50

GoogleCodeExporter commented 8 years ago
(although even if it works, there is clearly something funky going on with the 
error 
message

Original comment by marc.gravell on 17 Aug 2009 at 5:51

GoogleCodeExporter commented 8 years ago
Yeah, that seemed to fix it by removing the protocontract. Which indeed is 
somewhat
odd, but yeah. Thanks for the support, although it was a very far-out error 
message
as you described.

Thanks again!

Original comment by compus...@gmail.com on 19 Aug 2009 at 7:09

GoogleCodeExporter commented 8 years ago

Original comment by marc.gravell on 22 Apr 2010 at 9:19