How can I serialize an Entity Framework Code First Proxy when the class it is proxying is decorated with DataContractAttribute(IsReference = true)?
When using DataContractSerializer with ProxyContractResolver, I get the following:
The IsReference setting for type ‘System.Data.Entity.DynamicProxies.MyType_59A83378572C10D0B31B6892FB6C3E7428C4BA214322C7A77BD5E1EB19E529CA’ is ‘False’, but the same setting for its parent class ‘My.Namespace.MyType’ is ‘True’. Derived types must have the same value for IsReference as the base type. Change the setting on type
It seems that the EF Proxy Generator is not respecting the IsReference attribute, which I do need on the POCO (otherwise I end up with a stack overflow due to mutual referencing).
Is there any mechanism at all to serialize an EF Proxy under these circumstances? How?
I just did following very simple example and
ProxyDataContractResolverworks as expected – graph of proxied entities with cycles was correctly serialized.There must be something more complicated in your model to break the functionality – are all your entities marked with
DataContract(IsReference=true)?Note: I tested it in .NET 4.5.