无法反序列化以下对象图.在BinaryFormmater上调用deserialize方法时发生异常:System.Runtime.Serialization.SerializationException:
The constructor to deserialize an object of type 'C' was not found.
Run Code Online (Sandbox Code Playgroud)
C上有两个构造函数,我认为问题可能是:序列化Binaryformatter使用参数化和反序列化过程,它需要一个无参数化的.有黑客/解决方案吗?对象:
[Serializable]
public class A
{
B b;
C c;
public int ID { get; set; }
public A()
{
}
public A(B b)
{
this.b = b;
}
public A(C c)
{
this.c = c;
}
}
[Serializable]
public class B
{
}
[Serializable]
public class C : Dictionary<int, A>
{
public C()
{
}
public C(List<A> list)
{
list.ForEach(p => this.Add(p.ID, p));
}
}
Run Code Online (Sandbox Code Playgroud)
//序列化成功 …