Note that there are some explanatory texts on larger screens.

plurals
  1. PODeserialization of an array always gives an array of nulls
    text
    copied!<p>I have a custom abstract base class with sub classes that I've made serializable/deseriablizeable with ISerializable. When I do serialization/deserialization of single instances of this class' sub classes, everything works fine. However, when I do an array of them I always end up with an array of nulls on deserialization. Serialization is done with BinaryFormatter.</p> <p>The items are contained within a: </p> <pre><code>public ObservableCollection&lt;Trade&gt; Trades { get; private set; } </code></pre> <p>On serialization this is done in GetObjectData on the SerializationInfo parameter:</p> <pre><code>Trade[] trades = (Trade[])Trades.ToArray&lt;Trade&gt;(); info.AddValue("trades", trades); </code></pre> <p>And on deserialization this is done in the serialization constructor also on the SerializationInfo parameter:</p> <pre><code>Trade[] trades = (Trade[])info.GetValue("trades", typeof(Trade[])); foreach (Trade t in trades) { Trades.Add(t); } </code></pre> <p>Deserialization always gives me an array of nulls and as I mentioned earlier, a single item serializes and deseriaizes just fine with this code:</p> <p>Serialization (GetObjectData method):</p> <pre><code>info.AddValue("trade", Trades.First&lt;Trade&gt;()); </code></pre> <p>Deserialization (Serialization Constructor):</p> <pre><code>Trade t = (Trade)info.GetValue("trade", typeof(Trade)); Trades.Add(t); </code></pre> <p>Is this a common problem? I seem to find no occurrences of anyone else running in to it at least. Hopefully there is a solution :) and if I need to supply you with more information/code just tell me.</p> <p>Thanks!</p>
 

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