I'm trying to serialize a class that exposes a property as an interface. When I try to serialize the instance of the class the XmlSerializer throws an InvalidOperationException with the following message:
{"Cannot serialize member SerializationTest.ParkingLot.MyCar of type SerializationTest.ICar because it is an interface."}
I know there are severl ways to solve the problem. But I want to know why an interface cannot be serialized. There is a saying that "You can not serialize an interface. The problem is that an interface is an opaque type. There is no way for the serializer to know what to write out and more importantly what to create when it needs to serialize things back".
Could anyone explain more about this? Could you give me an example? Thank you in advance.