This code throws an exception. (Tested with mono 3.12 on linux, bois 1.8.1 from nuget package)
[Serializable]
public class PrimitiveDictionary1K
{
public Dictionary<int,PrimitiveType> Dict { get; set; }
}
[Serializable]
public class PrimitiveType
{
public bool BoolVar { get; set; }
public byte ByteVar { get; set; }
public short ShortVart { get; set; }
public int IntVar { get; set; }
public long LongVar { get; set; }
public char CharVar { get; set; }
public float FloatVar { get; set; }
public double DoubleVar { get; set; }
}
class MainClass
{
public static void Main (string[] args)
{
var ser = new BoisSerializer ();
byte[] data;
var dict = Create ();
using (MemoryStream ms = new MemoryStream ()) {
ser.Serialize (dict, ms);
data = ms.ToArray ();
}
PrimitiveDictionary1K des1;
using (MemoryStream ms = new MemoryStream (data)) {
des1=ser.Deserialize<PrimitiveDictionary1K>(ms);
}
Console.WriteLine ("length1={0}, length2={1}", dict.Dict.Count, dict.Dict.Count);
}
public static PrimitiveDictionary1K Create()
{
Random rnd = new Random (100);
PrimitiveDictionary1K dict = new PrimitiveDictionary1K(){Dict=new Dictionary<int, PrimitiveType> ()};
for (int i = 0; i < 1024; i++) {
int key;
do {
key = rnd.Next ();
} while (dict.Dict.ContainsKey (key));
dict.Dict.Add (key, new PrimitiveType () {
BoolVar = rnd.Next () % 2 == 0,
ByteVar = (byte)(rnd.Next () % 256),
CharVar = (char)(rnd.Next () % 65536),
DoubleVar = rnd.NextDouble (),
FloatVar = (float)rnd.NextDouble (),
IntVar = rnd.Next (),
LongVar = (long)rnd.Next () * (long)rnd.Next (),
ShortVart = (short)(rnd.Next () % 65536)
});
}
return dict;
}
}
System.ArgumentException: Destination array was not long enough. Check destIndex and length, and the array's lower bounds
at System.Array.Copy (System.Array sourceArray, Int32 sourceIndex, System.Array destinationArray, Int32 destinationIndex, Int32 length) [0x001c5] in /tmp/buildd/mono-3.12.0/mcs/class/corlib/System/Array.cs:970
at System.Array.Copy (System.Array sourceArray, System.Array destinationArray, Int32 length) [0x00022] in /tmp/buildd/mono-3.12.0/mcs/class/corlib/System/Array.cs:906
at Salar.Bois.PrimitivesConvertion.ReadInt32 (System.IO.BinaryReader reader, Int32 length) [0x00000] in :0
at Salar.Bois.PrimitivesConvertion.ReadVarInt32Nullable (System.IO.BinaryReader reader) [0x00000] in :0
at Salar.Bois.BoisSerializer.ReadObject (System.IO.BinaryReader reader, System.Type type) [0x00000] in :0
at Salar.Bois.BoisSerializer.ReadMember (System.IO.BinaryReader reader, Salar.Bois.BoisMemberInfo memInfo, System.Type memType) [0x00000] in :0
at Salar.Bois.BoisSerializer.ReadMember (System.IO.BinaryReader reader, System.Type memType) [0x00000] in :0
at Salar.Bois.BoisSerializer.ReadDictionary (System.IO.BinaryReader reader, System.Type memType) [0x00000] in :0
at Salar.Bois.BoisSerializer.ReadMember (System.IO.BinaryReader reader, Salar.Bois.BoisMemberInfo memInfo, System.Type memType) [0x00000] in :0
at Salar.Bois.BoisSerializer.ReadMembers (System.IO.BinaryReader reader, System.Object obj, Salar.Bois.BoisMemberInfo[] memberList, Int32 binaryMemberCount) [0x00000] in :0
at Salar.Bois.BoisSerializer.ReadObject (System.IO.BinaryReader reader, System.Type type) [0x00000] in :0
at Salar.Bois.BoisSerializer.ReadMember (System.IO.BinaryReader reader, Salar.Bois.BoisMemberInfo memInfo, System.Type memType) [0x00000] in :0
at Salar.Bois.BoisSerializer.ReadMember (System.IO.BinaryReader reader, System.Type memType) [0x00000] in :0
at Salar.Bois.BoisSerializer.Deserialize[PrimitiveDictionary1K](System.IO.Stream objectData) [0x00000] in :0
at ConsoleTest.MainClass.Main (System.String[] args) [0x0003b] in /home/sergey/Projects/SerializersBenchmarks/ConsoleTest/Program.cs:96