Removing deserialization of match types from different assemblies

If I have a pair of classes / interfaces defined in AssemblyA in the AssemblyA.Entities namespace:

 public IEntity { string Name { get; set; } } [Serializable] public Entity : IEntity { public string Name { get; set; } } 

And I serialize it to XML using XmlSerializer :

 var myEntities = new List<IEntity>(); // myEntities is populated somehow var data = XmlSerializationManager.Serialize(myEntities); // 'data' gets saved to disk somewhere as a file 

Then, if I duplicate the code / namespaces on AssemblyB so that I have the AssemblyA.Entities namespace and the same code:

 public IEntity { string Name { get; set; } } [Serializable] public Entity : IEntity { public string Name { get; set; } } 

If I try to deserialize previously serialized XML, will AssemblyB return the AssemblyB list? Or will it fail?

At what point does the serializer stop caring about what it deserializes? Can the assembly be different? Are namespaces different? Are there type names if the properties are called the same?

0
source share
1 answer

It will work. You will get an AssembyB object.

This, in essence, is how web services work, when the client creates classes using the information in wsdl, the client then deserializes the data from the soap message into these forest classes.

+1
source

Source: https://habr.com/ru/post/1236908/


All Articles