amoraller / protobuf-net

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

Problem using a compiled TypeModel with Inheritence and AsReference. #299

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Please include an e-mail address if this might need a dialogue!
==============
This is possibly related to the AsReference Inheritence known bug, although it 
only affects compiled type models so possibly not the same.

I've included a sample project which is as close to the way I've been using 
protobuf-net as possible without including the whole project I'm working on.  
It does seem to have an unusual way of defining the buffer but it works for me 
(most of the time!).

==============

What steps will reproduce the problem?

1. Use a class structure with inheritance
2. Use an AsReference field
3. Use a compiled TypeModel

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

I expect to be able to Serialize without any problem. Instead I see an 
InvalidCastException

What version of the product are you using? On what operating system?
Tested on both r480 and r510

==============

Please provide any additional information below.

This issue seems to come from the order in which types list is maintained 
differ in the RuntimeTypeModel and the TypeModel.

During BuildAllSerialisers() A NetObjectSerializer is constructed with a Key 
value index the RuntimeTypeModel's types list.

During Compile() the list is re-ordered if hasInheritence is true and written 
out to the compiled Assembly as the knowntypes property. 
The NetObjectSerializer.EmitWrite() writes out the key into the Write Method.

During Serialization the key is retrieved from the WriteMethod and used to look 
up the type in the knowntypes list (which was re-ordered after the key was 
written) so the key is now wrong. The Serializer try's to cast from the type 
being serialized to the type the key tells it that it should be serializing 
which fails.

Original issue reported on code.google.com by bub...@yahoo.co.uk on 11 Jul 2012 at 8:51

Attachments:

GoogleCodeExporter commented 9 years ago
This is now fixed (r595); you correctly spotted a later duplicate

Original comment by marc.gravell on 19 Oct 2012 at 9:24