qwertie / ecsharp

Home of LoycCore, the LES language of Loyc trees, the Enhanced C# parser, the LeMP macro preprocessor, and the LLLPG parser generator.
http://ecsharp.net
Other
172 stars 25 forks source link

Serialize SparseAList into session state #111

Closed matthiaszoellner closed 4 years ago

matthiaszoellner commented 4 years ago

I want to serialize a sparse list into ASP.Net Session state. While the SparseAList<T> class itself is marked Serializable, some used base classes are not.

Code to reproduce:

var list = new SparseAList<string>
{
    "Test"
};

var bf = new BinaryFormatter();
bf.Serialize(new MemoryStream(), list);

Results in a System.Runtime.Serialization.SerializationException, complaining, that Loyc.Collections.Impl.AListLeafBase``2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] is not marked as serializable.

Exception text is localized, so I can't provide the full english exception right now.

qwertie commented 4 years ago

Bug confirmed. I am fixing the problem now.

qwertie commented 4 years ago

A fixed version (with additional [Serializable] attributes) has been published as v27.2.1 on NuGet. Please verify that serialization is working now.

matthiaszoellner commented 4 years ago

First tests confirm it's working in my real world scenario 👍

Thanks for the quick response and fix. Much appreciated.

qwertie commented 4 years ago

Excellent. Please be careful how you use serialization, because the internal representation of an AList could change between versions of Loyc.Collections.