1

Closed

Fails to deserialize

description

[Serializable]
public class PlayerData {
public string Name;
public int[] someInts = new int[] { 4, 10, 20, 30, 45 };

public UnitData[] summon;
}

[System.Serializable]
public class UnitData {
public string name;
public byte RangeMin;
public byte RangeMax;
public byte Damage;
public byte Speed;
public byte HP;
public byte Actions;
public byte Cost;
}
/// <summary>
/// Serialize to bois to base64 string
/// </summary>
/// <param name="o">Any serializable object</param>
/// <returns>base 64 string</returns>
public static string SerializeBois( this object o ) {
    var boisSerializer = new BoisSerializer();
    using( var mem = new MemoryStream() ) {
        boisSerializer.Serialize( o, mem );
        return Convert.ToBase64String( mem.ToArray(), Base64FormattingOptions.None );
    }
}

public static T DeserializeBois<T>( this string s ) {
    byte[] b = Convert.FromBase64String( s );

    var boisSerializer = new BoisSerializer();
    using( var stream = new MemoryStream( b ) ) {
        //stream.Seek( 0, SeekOrigin.Begin );
        return boisSerializer.Deserialize<T>( stream );
    }
}



KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary`2[System.Type,Salar.Bois.BoisTypeCache+GenericConstructor].get_Item (System.Type key) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150)
Salar.Bois.BoisTypeCache.CreateInstance (System.Type t)
Salar.Bois.BoisSerializer.ReadObject (System.IO.BinaryReader reader, System.Type type)
Salar.Bois.BoisSerializer.ReadMember (System.IO.BinaryReader reader, Salar.Bois.BoisMemberInfo memInfo, System.Type memType)
Salar.Bois.BoisSerializer.ReadMember (System.IO.BinaryReader reader, System.Type memType)
Salar.Bois.BoisSerializer.Deserialize[PlayerData] (System.IO.Stream objectData)
ObjectSerializer.DeserializeBois[PlayerData] (System.String s) (at Assets/_Code/Helpers/ObjectSerializer.cs:52)
Player.DoSomeLoad () (at Assets/_CodeGame/Player.cs:54)
Closed Jan 4, 2015 at 5:45 AM by salar2k

comments

salar2k wrote Jul 15, 2014 at 7:17 PM

Thanks for the report, I'll check that and post results here.

salar2k wrote Jul 15, 2014 at 7:19 PM

What mono version are you using?

FreezyExp wrote Jul 16, 2014 at 7:13 AM

Using Unity3D 4.5, which uses Mono 2.6 which is sort of .NET 3.5

salar2k wrote Jan 4, 2015 at 5:45 AM

This bug should be fixed by now.
Please note that the project is moved to gitthub: https://github.com/salarcode/Bois