Anther Fast Serialization exception

Posts   
 
    
mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 23-Aug-2007 22:52:13   

I am so far unable to duplicate this exception with anything but my current object graph, but here it is...

at System.IO.__Error.EndOfFile()
at System.IO.BinaryReader.ReadString()
at SD.LLBLGen.Pro.ORMSupportClasses.SerializationReader.ReadTokenizedString(Int32 bucket)
at SD.LLBLGen.Pro.ORMSupportClasses.SerializationReader.ProcessObject(SerializedType typeCode)
at SD.LLBLGen.Pro.ORMSupportClasses.SerializationReader.ReadOptimizedObjectArrayPair(Object[]& values1, Object[]& values2)
at SD.LLBLGen.Pro.ORMSupportClasses.SerializationHelper.DeserializeEntityFields(SerializationReader reader, IEntityFields2 fields, Boolean isDirty, Boolean isNew)
at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.DeserializeOwnedData(SerializationReader reader, Object context)
at Coda.Entities.EntityClasses.CommonEntityBase.DeserializeOwnedData(SerializationReader reader, Object context) in CommonEntityBase.vb: line 853
at SD.LLBLGen.Pro.ORMSupportClasses.FastDeserializer.ReadReferencedEntities(EntityBase2 rootEntity)
at SD.LLBLGen.Pro.ORMSupportClasses.FastDeserializer.Deserialize(EntityBase2 entity)
at SD.LLBLGen.Pro.ORMSupportClasses.FastDeserializer.Deserialize(Byte[] serializedData, Object root)
at SD.LLBLGen.Pro.ORMSupportClasses.SerializationHelper.Deserialize(EntityBase2 entity, SerializationInfo info, StreamingContext context)
at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2..ctor(SerializationInfo info, StreamingContext context)
at Coda.Entities.EntityClasses.CommonEntityBase..ctor(SerializationInfo info, StreamingContext context) in CommonEntityBase.vb: line 54
at Coda.Entities.EntityClasses.ContractBranchEntity..ctor(SerializationInfo info, StreamingContext context) in ContractBranchEntity.vb: line 123
at Coda.Entities.EntityClasses.ContractualBranchEntity..ctor(SerializationInfo info, StreamingContext context) in ContractualBranchEntity.vb: line 242 
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 24-Aug-2007 10:38:55   

Could you please attach a simple repro project with exactly the same object graph?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 24-Aug-2007 10:41:06   

Also, what are you doing exactly in CommonEntityBase?

Frans Bouma | Lead developer LLBLGen Pro
mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 24-Aug-2007 16:39:25   

Otis wrote:

Also, what are you doing exactly in CommonEntityBase?

I am not doing any custom serialization in CommonEntityBase. Just in case there is something else I am doing that is causing this, I have emailed my CommonEntityBase.vb to your support email address.

This is bizarre, but the problem happens when I have the following situation: I have ParentEntity 1:N ChildEntity. I bind the ChildEntityCollection to a grid, bind a specific ChildEntity to some form controls and make an edit to one of its properties, ChildEntity.PropertyA. I then serialize the ParentEntity, deserialize, and thats where I get the exception. The exception comes from trying to deserialize the ChildEntity where I made an edit to PropertyA.

The bizarre part is that if no binding is involved, and I just make an edit to ChildEntity.PropertyA, ParentEntity will serialize and deserialize correctly.

I will try to come up with a sample that demonstrates this, but so far it is very difficult as I don't want to reproduce the exact environment that is in my real project (this would take foreever to reproduce).

mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 27-Aug-2007 00:44:03   

I'm able to reproduce this exception and have sent an example to your support email. It looks like the steps are: ParentEntity (1:N) ChildEntity

  1. Fetch ParentEntity with ChildEntityCollection
  2. Do a SaveFields on an entity in the ChildEntityCollection
  3. Write to one of the properties of the same ChildEntity
  4. Serialize the ParentEntity
  5. Deserialize the ParentEntity.

I'm looking into the reason this problem happens, but hopefully you guys can figure it out before me smile

mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 27-Aug-2007 01:55:55   

I think I found the problem. There is a line in EntityBase2.DeserializeOwnedData:

SerializationHelper.DeserializeEntityFields(reader, fields, IsDirty, reader.ReadBoolean());

that I think should be:

SerializationHelper.DeserializeEntityFields(reader, fields, reader.ReadBoolean(), _isNew );

At least, that fixes the problem for me. I don't have a set of unit tests to see if this breaks anything else, though.

simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 27-Aug-2007 06:48:19   

mikeg22 wrote:

I think I found the problem. There is a line in EntityBase2.DeserializeOwnedData:

SerializationHelper.DeserializeEntityFields(reader, fields, IsDirty, reader.ReadBoolean());

that I think should be:

SerializationHelper.DeserializeEntityFields(reader, fields, reader.ReadBoolean(), _isNew );

At least, that fixes the problem for me. I don't have a set of unit tests to see if this breaks anything else, though.

Hi Mike

This is my mistake I believe. bclubb pointed out the problem back in February and I suggested a fix which, looking back now, seems completely wrong - I got the reading a bool bit but put it in the wrong place. frowning

Sorry Frans - looks like a new batch of unit tests to catch all permutations for saved might help here.

Cheers Simon

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 27-Aug-2007 11:12:16   

Unit tests can only help in some degree: the scope of how many permutations you could have is simply too large. Better results are reported by reviewing the code (http://jvdb.org/blog/2007/08/02/code-inspections-reduce-defects-increase-understanding/) . So that's what I'll do first: read the code: what info does the write routine write out, what info does the read routine read. This should be in sync. It will also make me better understanding your code simple_smile .

Today I'll roll in the fix Mike found, so it can be included in todays build simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 27-Aug-2007 14:00:46   

Proposed fix by Mike is indeed correct: the serializer writes for every Fields object the IsDirty flag into the stream right before the fields itself, so for every Fields object read it has to be read before the fields are read and that value has to be passed on to the savedfields object.

The _isNew is already read so it should be passed to the deserialization routine .

Fixed in next build (released later today).

Frans Bouma | Lead developer LLBLGen Pro