user420667
user420667

Reputation: 6700

XmlDeserialization after renaming the classes involved

I have a bunch of xml serialized objects in a database.

But, I refactored and renamed the classes involved, so deserializing from the db is difficult.

I thought that by adding the term [XmlRoot("DB_Class_Name")] atop the renamed classes would fix the issue, but it doesn't appear to.

Is there a way to fix the issue using labels like [XmlRoot], [XmlElement] etc., without renaming my classes to their old classnames, and without writing a special deserialize function?

Also, are there any good sources on what is happening under the hood when using xmldeserializaiton and labels like [XmlRoot]?

Upvotes: 1

Views: 170

Answers (1)

John Saunders
John Saunders

Reputation: 161783

First of all, [XmlRoot] etc. aren't labels, they're attributes.

Second, [XmlRoot] only affects the class when that class is used as the root element of the document. It has no affect when an instance of that class is used as a child or other descendant.

Use [XmlType] on the class, or [XmlElement] on a property that is of the type of the class.

Upvotes: 3

Related Questions