none
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: https://social.msdn.microsoft.com/Forums/vstudio/en-US/be66c2ae-93f2-4b07-b88c-ba2f6f3c836e/how-to-support-forward-compatibility-of-newly-defined-types-which-are-stored-in-an-object?forum=wcf


    Friday, July 24, 2015 2:30 PM

Answers

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

    http://www.codeproject.com/Articles/22787/Custom-Serialization-Example

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

    http://www.codeproject.com/Articles/22787/Custom-Serialization-Example

    I hope that will be helpful to you.

    Best Regards

    Tracy Dj



    Monday, July 27, 2015 7:36 AM
    Moderator
  • 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.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/be66c2ae-93f2-4b07-b88c-ba2f6f3c836e/how-to-support-forward-compatibility-of-newly-defined-types-which-are-stored-in-an-object?forum=wcf
    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

    http://blogs.msdn.com/b/carlosfigueira/archive/2011/09/21/wcf-extensibility-data-contract-resolver.aspx

    2.Using a Data Contract Resolver

    https://msdn.microsoft.com/en-us/library/ee358759%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

    I hope that will be helpful to you.

    Best Regards,

    Tracy Dj


    Best Regards, Tracy Dj

    Tuesday, July 28, 2015 11:38 AM
    Moderator