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.

    <b>Deserialize:</b> 

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

    <span class="Apple-style-span" style="font-family:-webkit-monospace;">listBox1.Items.Add(b.ToString());</span>

    <span class="Apple-style-span" style="font-family:-webkit-monospace;"></span><b>Serialize:</b> 

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

    <span class="Apple-style-span" style="font-family:-webkit-monospace;">writer.Close();</span>

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

    <span class="Apple-style-span" style="font-family:-webkit-monospace;"></span>Regards, 

  • Replied 8 September 2017, 1:59 pm EST

    I'm using this code:

    ______________________________
    <span class="Apple-style-span" style="font-family:-webkit-monospace;"></span><b>Serialization</b>: version 3510

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

    ______________________________
    <span class="Apple-style-span" style="font-family:-webkit-monospace;"></span><b>Deserialization</b>: 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
        }
    }
    ______________________________
    <span class="Apple-style-span" style="font-family:-webkit-monospace;"></span><b>Exception</b>:

    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. 

       <runtime>

        <assemblyBinding>

          <dependentAssembly>

            <assemblyIdentity name="FarPoint.Win.Spread"/>

            <codebase version="4.0.3510.2008" href="file:///C:/Program Files/FarPoint Technologies/Spread.WinForms.4.dotNet35/v4.0.3510/Bin/FarPoint.Win.Spread.dll"/>

            <bindingRedirect oldVersion="4.0.3511.2008" newVersion="4.0.3510.2008"/>

          </dependentAssembly>

          <dependentAssembly>

            <assemblyIdentity name="FarPoint.Win"/>

            <codebase version="4.0.3510.2008" href="file:///C:/Program Files/FarPoint Technologies/Spread.WinForms.4.dotNet35/v4.0.3510/Bin/FarPoint.Win.dll"/>

            <bindingRedirect oldVersion="4.0.3511.2008" newVersion="4.0.3510.2008"/>

          </dependentAssembly>

        </assemblyBinding>

      </runtime>

    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