can't serialize/deserialize spread in different farpoint-versions

Posted by: hugoslav on 8 September 2017, 1:59 pm EST

  • Posted 8 September 2017, 1:59 pm EST

    Hi,

     i serialized my spread in version 3.5.3510. I updated my dlls to version 3.5.3511 and now i can't deserialize my spreads again!

    Is there a problem with serialize and deserialize in different farpoint-versions?

     thx

  • Replied 8 September 2017, 1:59 pm EST

    Hello,

    Are you using Binary Serialization or XML Serialization?

     

    Thanks,

  • Replied 8 September 2017, 1:59 pm EST

    I'm using Binary Serialization!

     thx for help

  • Replied 8 September 2017, 1:59 pm EST

    Hi, 

    I am using the following code to serialize and deserialize and it is working fine for me.

    Deserialize: 

    FarPoint.Win.Spread.Model.DefaultSheetDataModel dataModel = new FarPoint.Win.Spread.Model.DefaultSheetDataModel(5, 5);
    fpSpread1.ActiveSheet.Models.Data = dataModel;
    bool b;
    System.Xml.XmlDocument doc =
    new System.Xml.XmlDocument();
    doc.Load(
    "D:\\Temp\\myser.xml");
    System.Xml.XmlNode node;
    node = doc.FirstChild;
    while (!node.Name.Equals("DataModel"))
    node = node.NextSibling;
    System.Xml.XmlNodeReader r =
    new System.Xml.XmlNodeReader(node);
    r.Read();
    b = dataModel.Deserialize(r);

    listBox1.Items.Add(b.ToString());

    Serialize: 

    FarPoint.Win.Spread.Model.DefaultSheetDataModel dataModel = new FarPoint.Win.Spread.Model.DefaultSheetDataModel(8, 8);
    fpSpread1.ActiveSheet.Models.Data = dataModel;
    string fileName = "D:\\Temp\\myser.xml";
    System.IO.Stream stream = System.IO.File.Open(fileName, System.IO.FileMode.Create);
    System.Xml.XmlTextWriter writer =
    new System.Xml.XmlTextWriter(stream,     System.Text.Encoding.UTF8);
    writer.Formatting = System.Xml.Formatting.Indented;
    writer.Indentation = 2;
    writer.WriteStartDocument();
    writer.WriteStartElement(
    "DataModel");
    dataModel.Serialize(writer);
    writer.WriteEndElement();
    writer.WriteEndDocument();

    writer.Close();

    In case, if you are using some different approach, please provide a sample application that can replicate this issue on my computer.  

    Regards, 

  • Replied 8 September 2017, 1:59 pm EST

    I'm using this code:

    ______________________________
    Serialization: version 3510

    System.Runtime.Serialization.Formatters.Binary.BinaryFormatter b = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
    b.Serialize(ms, book.Sheets);    

    ______________________________
    Deserialization: version 3511

    System.Runtime.Serialization.Formatters.Binary.BinaryFormatter b = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
    b.Binder = new WorkbookBinder();
    b.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple;                                
    this.SheetViewCollection = b.Deserialize(stream) as FarPoint.Win.Spread.SheetViewCollection; // SerializationException

    ....

    public class WorkbookBinder : SerializationBinder
    {
       public override Type BindToType(string assemblyName, string typeName)
       {
          string name = string.Empty;
          Type type;

          assemblyName = "FarPoint.Win.Spread";

          name = string.Format( "{0}, {1}", typeName, assemblyName );
          type = Type.GetType( name );

          return type;      // the SheetViewCollection-Type in Version 3511
        }
    }
    ______________________________
    Exception:

    System.Runtime.Serialization.SerializationException: Der Member "parentModel" konnte nicht gefunden werden.
       bei System.Runtime.Serialization.SerializationInfo.GetElement(String name, Type& foundType)
       bei System.Runtime.Serialization.SerializationInfo.GetValue(String name, Type type)
       bei FarPoint.Win.Spread.Model.DefaultSheetDataModel..ctor(SerializationInfo info, StreamingContext context)
       --- Ende der internen Ausnahmestapel├╝berwachung ---
       bei System.RuntimeMethodHandle._SerializationInvoke(Object target, SignatureStruct& declaringTypeSig, SerializationInfo info, StreamingContext context)
       bei System.Reflection.RuntimeConstructorInfo.SerializationInvoke(Object target, SerializationInfo info, StreamingContext context)
       bei System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object obj, SerializationInfo info, StreamingContext context)
       bei System.Runtime.Serialization.ObjectManager.FixupSpecialObject(ObjectHolder holder)
       bei System.Runtime.Serialization.ObjectManager.DoFixups()
       bei System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
       bei System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
       bei System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
  • Replied 8 September 2017, 1:59 pm EST

    Hello, 

    You would need to setup the binding redirect to have the stream load with the correct version of the assembly. Below is the binding redirect I added to use the Binary Serialization successfully between 4.0.3511.2008 and 4.0.3510.2008 version of Spread. 

       

        

          

            

            

            

          

          

            

            

            

          

        

      

    I hope it helps.

    Regards, 

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels