This is a migrated thread and some comments may be shown as answers.

Struct serialization

5 Answers 60 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Pål
Top achievements
Rank 1
Pål asked on 16 Jan 2010, 09:23 PM
Hi!

During serialization of an ObjectContainer I get the following Exception:

Unable to cast object of type 'Telerik.OpenAccess.RT.StructFieldMarker' to type 'Telerik.OpenAccess.SPI.dataobjects.PersistenceCapable'.

I believe this has to do with classe having persistent structs attaced to them.

Here is the Class that won't serialize
[Persistent, Serializable]  
public class Order : ISerializable {  
 
    /// <summary> 
    /// The <see cref="Quantity"/> of this order  
    /// </summary> 
    private Quantity m_Quantity;  
 
(...)  

Here is the Quantity Struct:
[Persistent, Serializable]  
public struct Quantity : ISerializable {  
 
    /// <summary> 
    /// The decimal value of this Quantity  
    /// </summary> 
    private decimal m_Value;  
 
    /// <summary> 
    /// The Unit for this Quantity  
    /// </summary> 
    private Unit m_Unit;  
 
(...)  

And here is the mapping:
<class name="Order">  
  <extension key="db-inheritance" value="vertical" /> 
  <extension key="db-table-name" value="Order" /> 
  <field name="m_Quantity">  
    <extension key="field" value="m_Unit">  
      <extension key="db-column">  
        <extension key="db-column-name" value="Quantity.UnitID" /> 
      </extension> 
    </extension> 
    <extension key="field" value="m_Value">  
      <extension key="db-column">  
        <extension key="db-column-name" value="Quantity.Value" /> 
      </extension> 
      <extension key="null-value" value="exception" /> 
    </extension> 
  </field> 
(...)  
</class> 
 

Please help.

Thanks

Pål

5 Answers, 1 is accepted

Sort by
0
Pål
Top achievements
Rank 1
answered on 17 Jan 2010, 09:32 PM
Hi again.

Update:

I have located the source of the error (i think) and it occurs on deserialization of "ObjectContainer" when it contains persistent structs with persistent references in them (se my "Quantity" struct above, which contains a reference to a persistent "Unit").

Anyway, the exception is initiated from "Telerik.OpenAccess.RT.DisconnectedStateManager", method: "CheckSerializationConsistency" (se below). I believe the indexes retrieved in the "numArray" are wrong and so a "StructFieldMarker" is passed to "helper.extractReferences(...)" which will later try to cast it as a "PersitentCapable" object.

Here is where the fatal call is made from (and where the erronus array indexes are retrieved):
internal void CheckSerializationConsistency(ReferenceCollector coll)  
    {  
      ReferenceHelper helper = this.referenceHelper();  
      int[] numArray = helper.getReferencingFieldNums();  
      for (int i = numArray.Length - 1; i >= 0; i--)  
      {  
        int index = numArray[i];  
        object x = this.data[index];  
        if ((x != null) && (x != invalidFieldContentMarker))  
        {  
          helper.extractReferences(x, index, coll, this);  
        }  
      }  
    } 

This is the source of the actual Exception. x variable is passed a "StructFieldMarker":
    public override void extract(object x, ReferenceCollector coll, StateManager sm)  
    {  
      coll.Add((PersistenceCapable) x, base.slot, false, sm);  
    } 

If the array values are messed up on serialization or deserialization, I don't know, but I think it's one of them.

Hope this helps in locating the bug.

Thanks

Pål
0
Jan Blessenohl
Telerik team
answered on 18 Jan 2010, 05:30 PM
Hello Pål,
I can reproduce your problem and have fixed it. I still have to write some tests and will inform you about the availability later.

Workaround is to not use structs at all. Is it possible to use a class instead of a struct?

All the best,
Jan Blessenohl
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Pål
Top achievements
Rank 1
answered on 18 Jan 2010, 05:36 PM
Excellent. That's great. :-)

No problem, I can use other classes to test out serialization for now.

I can still use structs, as long as they only contain valuetypes.

Thanks

Pål
0
Pål
Top achievements
Rank 1
answered on 24 Mar 2010, 10:16 AM
Hi.

Has this fix been included in the Q1 2010 release?

Pål
0
Jan Blessenohl
Telerik team
answered on 26 Mar 2010, 12:32 PM
Hi Pål,
Yes, the fix is part of the Q1 release.

Sincerely yours,
Jan Blessenohl
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
General Discussions
Asked by
Pål
Top achievements
Rank 1
Answers by
Pål
Top achievements
Rank 1
Jan Blessenohl
Telerik team
Share this question
or