Struct serialization

Thread is closed for posting
6 posts, 0 answers
  1. Pål
    Pål avatar
    53 posts
    Member since:
    Sep 2012

    Posted 16 Jan 2010 Link to this post

    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
  2. Pål
    Pål avatar
    53 posts
    Member since:
    Sep 2012

    Posted 17 Jan 2010 Link to this post

    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
  3. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 18 Jan 2010 Link to this post

    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.
  4. Pål
    Pål avatar
    53 posts
    Member since:
    Sep 2012

    Posted 18 Jan 2010 Link to this post

    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
  5. Pål
    Pål avatar
    53 posts
    Member since:
    Sep 2012

    Posted 24 Mar 2010 Link to this post

    Hi.

    Has this fix been included in the Q1 2010 release?

    Pål
  6. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 26 Mar 2010 Link to this post

    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.
Back to Top