The sort of the nodes/attributes in the serialized xml file, some times change.

Jul 10 at 5:59 PM
Edited Jul 10 at 6:00 PM
Hi, I have a small problem when I try to serialize a my class.
Often the serialization works fine, all the nodes maintain the sort order also after more saving but in some cases I have seen in the config file one section that, normally is at the end of the file, in another position.
It is only a different location in the XML file without problems, but I have the necessity to compare the xml with a previous version to check the changes and often I'm not able to do this in a short way because I have many 'section' in a different position.
The same problem is present for the attribute of the nodes.
For example I have two fields, 'MinValue' and 'MaxValue' and often change the position inside the node.

There is a possibility to add a property to enable the serialization with the same order (for example with an alphabetic order, or with the same order of the first serialization)?

PS: I'm using the standard serialization and not a 'customized' serialization.

Regards.
Coordinator
Jul 11 at 1:20 AM
Hi,

The order of fields serialized are fixed and is the same order that .NET reflects properties. Actually my unit tests rely on that. Have you by any chance reordered your class properties?

The only other exception is when you serialize elements of a data-structures that uses hash-table internally. Examples are Dictionary, HashSet and Hashtable.
Are you, using Dictionary, HashSet, Hashtable, or a similar data structure in your class?

Regards,
Sina
Jul 11 at 7:32 AM
Hi
I try to explain better the classes I'm using.
For the serialization of some parameters, where I need also the information about the Minimum and Maximum value, I have created a generic class that exposes the properties, serializable, MinValue, MaxValue and Value.
All these three properties have the attribute [YAXAttributeForClass] to serialize as attribute of the node.
Often I obtain, in the xml serialized, the swap of the position for Min, Max or Value attribute.
I don't know if the usage of a generic class be part of the exception that you have mentioned

For the 'main' nodes it is different because all nodes are specific 'classes' but, as I wrote in the first post, in some cases the position change.
To explain better, I have the main class 'Settings' that expose as properties other classes (ApplicationSettings, ...., DebugSettings)
The DebugSettings class is exposed as last property of the Settings class, but in some case, in the xml file, the DebugSettings node is located before the ApplicationSettings node.

I'm not using the very last release of the YAXLib, one test that I can do it is to update my library and check if the problem disappears.

Regards
Luigi.
Coordinator
Jul 16 at 3:37 AM
Hi Luigi,

I'm afraid I couldn't replicate this issue. It'll be great if you can send me your C# class definition, with some sample values for different properties, and show me how I can replicate this.

Regards,
Sina