Search code examples
c#xmlserializationdotfuscator

XML Serialization with Dotfuscator


I am trying to serialize a couple of nested classes to and from an XML file.

My load and save methods use XmlSerializer/TextWriter/TextReader. This works fine if I don't use Dotfuscator. But if I use Dotfuscator, it fails to write the classes to the file and I only get the root XML tags.

I have since tried explicitly naming each field like so:

[XmlRoot("ParentClass")]
public class ParentClass
{
    [XmlArray("ChildClasses")]
    public List<ChildClass> ChildClasses;
}

[XmlType("ChildClass")]
public class ChildClass
{
    [XmlElement("Property")]
    public string Property;
}

Basically, if it's getting serialized, I've given it explicit naming. However I tested this and it still doesn't work with the Dotfuscator. Anyone know how to get it to work?


Solution

  • XML Serialization uses reflection, so the fact that Dotfuscator can rename these classes is probably causing an issue.

    Try this:

    [Obfuscation(Feature = "renaming", Exclude = true)]
    public class ParentClass
    {
       ...
    

    Decorate each class that will be XML Serialized with this decorator.