Note that there are some explanatory texts on larger screens.

plurals
  1. PO.net serialisation different frameworks
    primarykey
    data
    text
    <p>There is an error very simple to reproduce when serializing and deserializing with different .net frameworks (framework 2 and 4). When I serialize a System.Globalization.CompareInfo with framework 2 and try to deserialize it with framework 4 there will be an OverflowException. The code is as follows:</p> <pre><code>private void button1_Click(object sender, EventArgs e) { CompareInfo ci = CompareInfo.GetCompareInfo("de-DE"); Stream stream = File.Open("C:\\Temp\\test.bin", FileMode.Create); BinaryFormatter formatter = new BinaryFormatter(); formatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple; formatter.TypeFormat = System.Runtime.Serialization.Formatters.FormatterTypeStyle.XsdString; formatter.Serialize(stream, ci); stream.Close(); } private void button2_Click(object sender, EventArgs e) { Stream stream = File.Open("C:\\Temp\\test.bin", FileMode.Open); BinaryFormatter formatter = new BinaryFormatter(); CompareInfo ci = (CompareInfo)formatter.Deserialize(stream); stream.Close(); } </code></pre> <p>When I do this with the same version (2 or 4) it works as expected. When I save the file with framework 2 and try to open it with framework 4 i will get the OverflowException. Now I am looking for a workaround (since there are thousands of files writen with framework 2.0 at our customers). I tried an approach like in <a href="https://stackoverflow.com/questions/2174591/net-c-how-to-add-a-custom-serialization-attribute-that-acts-as-iserializable">How to add a custom serialization attribute that acts as ISerializable interface</a> but with no success. Any Ideas?</p> <p>I am sorry, I omitted the two lines that made may code crash:</p> <pre><code> formatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple; formatter.TypeFormat = System.Runtime.Serialization.Formatters.FormatterTypeStyle.XsdString; </code></pre> <p>because I thought they were not necessary. Now I updated the code and it is crashing. It doesn't help to include these lines when reading the file.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload