Data Contract Resolver is not called for Data Contracts which are added as Data Members RRS feed

  • Question

  • Hi,

    My problem is with Data Contract Serializer and its Data Contract Resolver. For simple Data Contracts when they have Data Members, it works perfectly and the overridden methods of Data Contract Resolver are called. However, when you have complex Data Contract types, i.e., when you have a Data Contract which has a Data Member which itself is a Data Contract, the overridden methods are not called! 

    My initial problem is:

    Friday, July 24, 2015 2:30 PM


All replies

  • Hi Arash.Robotmaster,

    According to your description, if you don't want to use Known Types,

     prehaps you can custom serialization.

    For more infromation ,  you can refer to the following Links:

    1.Custom Serialization

    2.Serialization in C# .NET I - Custom Serialization

    I hope that will be helpful to you.

    Best Regards

    Tracy Dj

    Monday, July 27, 2015 7:36 AM
  • Thanks for you answer. These solutions still will not solve my main problem.

    My main problem is: I want to support forward compatibility of adding new custom types (new classes) defined in the newer versions when stored in an object property.

    The problem is that if you store a type in an object and pass it to serialization, it also stores its run-time type which causes an exception when the previous version tries to load it.
    Monday, July 27, 2015 2:17 PM
  • Hi Arash.Robotmaster,

    Ok, When the serializer is set up with a DataContractResolver, during serialization, if the serializer finds out an object where the actual type doesn’t match the declared type, it will ask the resolver whether it can process it, by calling TryResolveType. If the resolver can do that, then the serializer will use the resulting name and namespace to write out the XML for that type in the type hint attribute (an attribute with local name “type” and namespace . During deserialization, if a type hint attribute is found, then the serializer will call the ResolveName method on the resolver, where it can decide which type to use.

    For more information,please refer to the following articles:

    1.WCF Extensibility – Data Contract Resolver

    2.Using a Data Contract Resolver

    I hope that will be helpful to you.

    Best Regards,

    Tracy Dj

    Best Regards, Tracy Dj

    Tuesday, July 28, 2015 11:38 AM