I keep getting a System.Runtime.Serialization.SerializationException error when using this code in C#. Specifically, I'm trying to deserialize a Dictionary<byte, object> but always run into this issue. Any help would be appreciated.
var Data = FromIL2CPPToManaged<Dictionary<byte, object>>(__1);
Data[6] = BufferRW.Vector3ToBytes(new Vector3(1f, 1f, 1f));
__1 = ObjectFromDictionary<Il2CppSystem.Object>(Data);
public static T FromByteArray<T>(byte[] data)
{
if (data == null) return default;
var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
using var serializationStream = new System.IO.MemoryStream(data);
return (T)binaryFormatter.Deserialize(serializationStream);
}
public static byte[] ToByteArray(object obj)
{
if (obj == null) return null;
var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
var memoryStream = new System.IO.MemoryStream();
binaryFormatter.Serialize(memoryStream, obj);
return memoryStream.ToArray();
}
public static T IL2CPPFromByteArray<T>(byte[] data)
{
if (data == null) return default;
var binaryFormatter = new Il2CppSystem.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
var serializationStream = new Il2CppSystem.IO.MemoryStream(data);
return (T)(object)binaryFormatter.Deserialize(serializationStream);
}
public static T FromIL2CPPToManaged<T>(Il2CppSystem.Object obj)
{
return FromByteArray<T>(ToByteArray(obj));
}
public static T FromManagedToIL2CPP<T>(object obj)
{
return IL2CPPFromByteArray<T>(ToByteArray(obj));
}
public static byte[] targetByteArray = null;
public static byte[] e1targetByteArray = null;
public static Il2CppSystem.Object ConvertByteArrToIl2CppObject(byte[] byteArray)
{
string json = System.Text.Encoding.Default.GetString(byteArray);
Il2CppSystem.Object obj = (Il2CppSystem.Object)JsonConvert.DeserializeObject(json);
return obj;
}
I'm not sure what's causing this error nor how to fix it. The error message specifically says System.Runtime.Serialization.SerializationException: Type 'UnhollowerBaseLib.Il2CppObjectBase' in Assembly 'UnhollowerBaseLib, Version=0.4.18.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.. Any advice on how to proceed would be greatly appreciated.