I'm trying to add XML serialization to a fairly trivial class structure in C#. Essentially, there's a single instance of a root class (call it AClass), which holds a List of several instances of some other class (call it AnotherClass):
[XmlRoot("RootNode")]
public class AClass {
[XmlElement("ListNode")]
internal List otherObjects { get; set; }
}
public class AnotherClass {
[XmlAttribute("Name")]
internal string name { get; set; }
}
When serializing, I'd like for both these classes to be serialized together - that is, if I serialize AClass, its list of AnotherClass gets serialized as well (see this question).
I have this mostly working, but the problem is that during serialization, XmlSerializer only seems to want to deal with public
properties of the class - it doesn't serialize AnotherClass at all if the list is declared internal
.
I tried making the assembly's internals visible to the serializer:
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("System.Xml")]
That didn't seem to do anything. Is there a way I can get XmlSerializer to recursively serialize lists of objects that are declared internal?