Open GoogleCodeExporter opened 9 years ago
This problem also affects serialization of surrogates with AsReference=true.
When we store surrogate which have field that references back to it, it doesnt
detect it as same reference (because it compares stored in cache surrogate with
final class), so it tries to store it once more.
Heres a repro code, posting it here, because this two problems are closely
related.
[ProtoContract]
public class B_Surr
{
public static implicit operator B (B_Surr s)
{
if ( s == null )
return null;
var b = new B();
b.reference = s.reference;
return b;
}
public static implicit operator B_Surr (B b)
{
if ( b == null )
return null;
var s = new B_Surr();
s.reference = b.reference;
return s;
}
[ProtoMember(1, AsReference = true)]
B reference;
}
public class B
{
public B reference;
}
[ProtoContract]
public class A
{
[ProtoMember(1, AsReference = true)]
public B b;
}
class Program
{
static void Main()
{
RuntimeTypeModel.Default.Add(typeof(B), true).SetSurrogate(typeof(B_Surr));
B b = new B();
b.reference = new B();
b.reference.reference = b;
Serializer.DeepClone (new A() { b = b } );
}
}
gives Invalid Cast Exception from "B_Surr" to "B"
Thanks. Sergey
Original comment by ish...@mail.ru
on 23 Jan 2013 at 7:09
Original issue reported on code.google.com by
ish...@mail.ru
on 23 Jan 2013 at 6:39