Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 893
Trevor Elliott Avatar asked Feb 21 '26 11:02

Trevor Elliott


1 Answers

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.

like image 81
DanTheMan Avatar answered Feb 22 '26 23:02

DanTheMan