I am trying to serialize a Class like this:
[DataContract]
public class GenericFlow
{
[DataMember]
public ISource Source { get; set; }
[DataMember]
public IList<IFilter> Filters { get; set; }
}
When i seralize an instance of this object, everything goes right but if i try to deserialize i get an error. I am using Mono 2.6 for my tests, this is the error on the mono platform :
Stacktrace:
Native stacktrace:
/usr/bin/mono() [0x48563b]
/usr/bin/mono() [0x4d275f]
/lib/libpthread.so.0(+0xfb40) [0x7fd5f8d6eb40]
/usr/bin/mono(mono_object_get_virtual_method+0x174) [0x4f5744]
/usr/bin/mono() [0x555524]
[0x41632228]
Debug info from gdb:
If i remove the DataMember Attribute from the Source Property, deserialization works.
Taking a look at the json string produced during serialization, i can see that each item in the Filters list include a "__type" attribute especifing the concrete class that implements IFilter. But this is not true with the property "Source" of type ISource where the property "__type" is missing, so the desarialization process doesnt know which concrete class use to recreate the property.
Since i dont have a windows box handy, i dont know if this is mono specific problem or maybe i am missing something here.
How should i tell DataContractJsonSerializer to include the "__type" attribute in the Source Property?
Thanks in advance,
UPDATE:
Investigating a bit more, now i can force DataContractJsonSerializer to always emit type information calling the constructor with alwaysEmitTypeInformation=true. But the problem persists. Any ideas?