I have an object with (de-) serializing its configuration through system.xml.serializer
The configuration in the class is as follows:
public struct Phase { public Int16 Trafo; public KorrekturWerte Spannung; public KorrekturWerte Strom; [XmlArray("Min")] public double[] Min; [XmlArray("Max")] public double[] Max; public bool CheckThis; } public class ParameterHardware { public string WAGOId = "00:30:DE:05:33:CB"; public Byte Phasen = 0x07; public Phase L1; public Phase L2; public Phase L3; }
(De-) Serializing this on a WindowsXP system works very well, but on Windows CE the Min / Max-Array just crashes after deactivation and then it is reserialized ("CheckThis" was put there as a test and follows after serializing the "Strom" values). Since KorrekturWerte is again a structure, depth cannot be a problem. [XmlArray ...] was not in my first version, it's just from another test.
Edit:
The problem is not (only) in serialization. Trying to access Min [...] I get a null reference error.
Perhaps this is not clear: I have serialized a class that contains all the values. Destroy it to initialize the class, and then repeat it as a debug check. Now the fields are missing. (The original file was serialized in XP, where it works correctly)
Changing a double [] to a list does not help. (Same result)
xml files: Original:
00: 30: DE: 05: 53: 65 1 50 -0.2 1 0.004 0.994 0 0 0 0 0 500 32 15000 15000 1 true 50 0 1 0 1 0 0 0 0 0 500 32 15000 15000 1 50 0 1 0 1 0 0 0 0 0 500 32 15000 15000 1
Re-initialization (sorry CE is serialized on one line):
<?xml version="1.0" encoding="utf-8"?><ClassTest_FCT_Extern xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Hardware><WAGOId>00:30:DE:05:53:65</WAGOId><Phasen>1</Phasen><L1><Trafo>50</Trafo><Spannung><Offset>-0.2</Offset><Steigung>1</Steigung></Spannung><Strom><Offset>0.004</Offset><Steigung>0.994</Steigung></Strom><CheckThis>true</CheckThis></L1><L2><Trafo>50</Trafo><Spannung><Offset>0</Offset><Steigung>1</Steigung></Spannung><Strom><Offset>0</Offset><Steigung>1</Steigung></Strom><CheckThis>false</CheckThis></L2><L3><Trafo>50</Trafo><Spannung><Offset>0</Offset><Steigung>1</Steigung></Spannung><Strom><Offset>0</Offset><Steigung>1</Steigung></Strom><CheckThis>false</CheckThis></L3></ClassTest_FCT_Extern>
Sorry for putting all the slices in slices. Here is the serialization code (using System.Xml.Serialization;)
try { fstream = new FileStream(filepath, FileMode.Open, FileAccess.Read); reader = new XmlTextReader(fstream); serializer = new XmlSerializer(typeof(T)); retobj = (T)serializer.Deserialize(reader); } catch (Exception e) { Debug("Serialization: "+e.ToString()); retobj = Activator.CreateInstance<T>(); }
Debugging is not called, so no errors occur.
source share