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

    <p>Hi,</p><p> 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!</p><p>Is there a problem with serialize and deserialize in different farpoint-versions?</p><p> thx <br></p>
  • Replied 8 September 2017, 1:59 pm EST

    <p>Hello, </p><p>Are you using Binary Serialization or XML Serialization?</p><p> </p><p>Thanks, <br></p>
  • Replied 8 September 2017, 1:59 pm EST

    <p>I'm using Binary Serialization!</p><p> thx for help <br></p>
  • Replied 8 September 2017, 1:59 pm EST

    <p>Hi, </p><p>I am using the following code to serialize and deserialize and it is working fine for me. </p><p><b>Deserialize:</b> </p><p><code class="CS">FarPoint.Win.Spread.Model.DefaultSheetDataModel dataModel = <font color="blue">new</font> <font color="black">FarPoint.Win.Spread.Model.DefaultSheetDataModel(5, 5);<br>fpSpread1.ActiveSheet.Models.Data = dataModel;<br></font><font color="blue">bool</font> <font color="black">b;<br>System.Xml.XmlDocument doc =</font> <font color="blue">new</font> <font color="black">System.Xml.XmlDocument();<br>doc.Load(</font><font color="#a31515">"D:\\Temp\\myser.xml"</font><font color="black">);<br>System.Xml.XmlNode node;<br>node = doc.FirstChild;<br></font><font color="blue">while</font> <font color="black">(!node.Name.Equals(</font><font color="#a31515">"DataModel"</font><font color="black">))<br>node = node.NextSibling;<br>System.Xml.XmlNodeReader r =</font> <font color="blue">new</font> <font color="black">System.Xml.XmlNodeReader(node);<br>r.Read();<br>b = dataModel.Deserialize(r);<br></font></code></p><p><span class="Apple-style-span" style="font-family:-webkit-monospace;">listBox1.Items.Add(b.ToString());</span></p><p><span class="Apple-style-span" style="font-family:-webkit-monospace;"></span><b>Serialize:</b> </p><code class="CS">FarPoint.Win.Spread.Model.DefaultSheetDataModel dataModel = <font color="blue">new</font> <font color="black">FarPoint.Win.Spread.Model.DefaultSheetDataModel(8, 8);<br>fpSpread1.ActiveSheet.Models.Data = dataModel;<br></font><font color="blue">string</font> <font color="black">fileName =</font> <font color="#a31515">"D:\\Temp\\myser.xml"</font><font color="black">;<br>System.IO.Stream stream = System.IO.File.Open(fileName, System.IO.FileMode.Create);<br>System.Xml.XmlTextWriter writer =</font> <font color="blue">new</font> <font color="black">System.Xml.XmlTextWriter(stream,     System.Text.Encoding.UTF8);<br>writer.Formatting = System.Xml.Formatting.Indented;<br>writer.Indentation = 2;<br>writer.WriteStartDocument();<br>writer.WriteStartElement(</font><font color="#a31515">"DataModel"</font><font color="black">);<br>dataModel.Serialize(writer);<br>writer.WriteEndElement();<br>writer.WriteEndDocument();<br></font></code><p><span class="Apple-style-span" style="font-family:-webkit-monospace;">writer.Close();</span></p><p>In case, if you are using some different approach, please provide a sample application that can replicate this issue on my computer.  </p><p><span class="Apple-style-span" style="font-family:-webkit-monospace;"></span>Regards, </p>
  • Replied 8 September 2017, 1:59 pm EST

    I'm using this code:<br><br>______________________________<br><span class="Apple-style-span" style="font-family:-webkit-monospace;"></span><b>Serialization</b>: version 3510<br><br>System.Runtime.Serialization.Formatters.Binary.BinaryFormatter b = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();<br>b.Serialize(ms, book.Sheets);    <br><br>______________________________<br><span class="Apple-style-span" style="font-family:-webkit-monospace;"></span><b>Deserialization</b>: version 3511<br><br>System.Runtime.Serialization.Formatters.Binary.BinaryFormatter b = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();<br>b.Binder = new WorkbookBinder();<br>b.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple;                                <br>this.SheetViewCollection = b.Deserialize(stream) as FarPoint.Win.Spread.SheetViewCollection; // SerializationException<br><br>....<br><br>public class WorkbookBinder : SerializationBinder<br>{ <br>   public override Type BindToType(string assemblyName, string typeName)<br>   {<br>      string name = string.Empty;<br>      Type type;<br><br>      assemblyName = "FarPoint.Win.Spread";<br><br>      name = string.Format( "{0}, {1}", typeName, assemblyName );<br>      type = Type.GetType( name );<br><br>      return type;      // the SheetViewCollection-Type in Version 3511<br>    }<br>}<br>______________________________<br><span class="Apple-style-span" style="font-family:-webkit-monospace;"></span><b>Exception</b>:<br><br>System.Runtime.Serialization.SerializationException: Der Member "parentModel" konnte nicht gefunden werden.<br>   bei System.Runtime.Serialization.SerializationInfo.GetElement(String name, Type& foundType)<br>   bei System.Runtime.Serialization.SerializationInfo.GetValue(String name, Type type)<br>   bei FarPoint.Win.Spread.Model.DefaultSheetDataModel..ctor(SerializationInfo info, StreamingContext context)<br>   --- Ende der internen Ausnahmestapel├╝berwachung ---<br>   bei System.RuntimeMethodHandle._SerializationInvoke(Object target, SignatureStruct& declaringTypeSig, SerializationInfo info, StreamingContext context)<br>   bei System.Reflection.RuntimeConstructorInfo.SerializationInvoke(Object target, SerializationInfo info, StreamingContext context)<br>   bei System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object obj, SerializationInfo info, StreamingContext context)<br>   bei System.Runtime.Serialization.ObjectManager.FixupSpecialObject(ObjectHolder holder)<br>   bei System.Runtime.Serialization.ObjectManager.DoFixups()<br>   bei System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)<br>   bei System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)<br>   bei System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
  • Replied 8 September 2017, 1:59 pm EST

    <p>Hello, </p><p>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. </p><p>   <runtime></p><p>    <assemblyBinding></p><p>      <dependentAssembly></p><p>        <assemblyIdentity name="FarPoint.Win.Spread"/></p><p>        <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"/></p><p>        <bindingRedirect oldVersion="4.0.3511.2008" newVersion="4.0.3510.2008"/></p><p>      </dependentAssembly></p><p>      <dependentAssembly></p><p>        <assemblyIdentity name="FarPoint.Win"/></p><p>        <codebase version="4.0.3510.2008" href="file:///C:/Program Files/FarPoint Technologies/Spread.WinForms.4.dotNet35/v4.0.3510/Bin/FarPoint.Win.dll"/></p><p>        <bindingRedirect oldVersion="4.0.3511.2008" newVersion="4.0.3510.2008"/></p><p>      </dependentAssembly></p><p>    </assemblyBinding></p><p>  </runtime></p><p>I hope it helps. </p><p>Regards, </p>
Need extra support?

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

Learn More

Forum Channels