luheyun / protobuf-net

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

Protobuf.net inheritance problem #101

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi, We are using protobuf.net v1 using linq-to-sql with auto-generated c#
code which has a 4 level class hierarchy.  This is done via the .dbml file
type.

So something like:
class Security
class ListedSecurity : Security
class Future : ListedSecurity
etc...

Unfortunately when attempting to serialize a list of these classes we get
the following exception.

                    throw new ProtoException(
                        "Callbacks are only supported on the root contract
type in an inheritance tree; consider implementing callbacks as virtual
methods on " +
                        root.FullName);

Since the code is auto generated we are forced to manually delete all
OnDeserializingAttribute instances.

Could you please advise if you this could be fixed?
Best,
Alex. 
abesidski@hotmail.com

Original issue reported on code.google.com by abesid...@gmail.com on 25 Mar 2010 at 9:35

GoogleCodeExporter commented 9 years ago
Right, I can see how that would be a problem. Those are LINQ-to-SQL classes, 
right? 
(I'm just trying to figure out if the best approach is to allow it to silently 
ignore 
them, or whether it needs to include them).

I'll try to reproduce here (with DBML) so that I can see the best option. 
Annoyingly, 
v2 provides much better flexibility over what it includes, but the inheritance 
stuff is 
still a while away in v2. So I'll have to fit it in v1 ;-p

Original comment by marc.gravell on 26 Mar 2010 at 8:29

GoogleCodeExporter commented 9 years ago
Mark, yes -- these are Linq-to-Sql classes.
For my purposes it really doesn't matter whether you invoke initializers at 
all, but 
if possible it would seem best to invoke the most derived initializer on a 
given 
class instance.
Thank you.

Original comment by abesid...@gmail.com on 28 Mar 2010 at 2:43

GoogleCodeExporter commented 9 years ago

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