![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
OK I'm not sure how explain this without giving hundreds of lines of code. basically I have a main class that I want to serialize. It's constructor creates more classes that I also want serialized. public Mainclass{ public subclass1 class1; public MainClass() { class1 = new subclass1() } } //Now that subclass wants to create more classes public subclass1 { public string blah; public subclass2[] class2array; public subclass1() { blah = "blah"; class2array = new class2array[2] for (int i =0; i<2; i++) { class2array[i] = new subclass2(i.ToString()); } } } //which creates public subclass2{ public string name; public subclass2(string inName) { name = in Name; } public subclass2() { // default constructor } } Now when I serialize this thing I'd hope I get back something like ?xml version="1.0" encoding="utf-8"? MainClass xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001... subClass1 blah>blah</blah subclass2 name>0</name /subclass2 subclass2 name>1</name /subclass2 /subClass1 /MainClass Running this in the regular framework I do get that back However running this in the compact framework I get back MainClass xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001... subClass1 blah>blah</blah /subClass1 /MainClass The difference seems to be coming from within the loops but I can't see what Is going wrong there. Is this a known thing? I didn't post my actual code since it's miles long but this is the general idea of what is failing. If I throw in a debug message in the constructor for subClass2 It does fire so it is getting all the way down there it's just not showing up in the XML at the end. Any idea? sorry for the cross post but the XML guys seem to not answer many CF questions. |
#3
| |||
| |||
|
|
This is not what I see. I compiled your code (fixed a couple of typos) and got the following xml: ?xml version="1.0"? MainClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" class1 class2array subclass2 name>0</name /subclass2 subclass2 name>1</name /subclass2 /class2array blah>blah</blah /class1 /MainClass>" The serialization code looked like this: XmlSerializer xs = new XmlSerializer(typeof(MainClass)); MemoryStream ms = new MemoryStream(); xs.Serialize(ms, new MainClass()); byte[] data = ms.ToArray(); Debug.WriteLine(Encoding.ASCII.GetString(data, 0, data.Length)); "jamie" <strider3700 (AT) nospam (DOT) nospam> wrote in message news:eQjUrifTGHA.4308 (AT) TK2MSFTNGP10 (DOT) phx.gbl... OK I'm not sure how explain this without giving hundreds of lines of code. basically I have a main class that I want to serialize. It's constructor creates more classes that I also want serialized. public Mainclass{ public subclass1 class1; public MainClass() { class1 = new subclass1() } } //Now that subclass wants to create more classes public subclass1 { public string blah; public subclass2[] class2array; public subclass1() { blah = "blah"; class2array = new class2array[2] for (int i =0; i<2; i++) { class2array[i] = new subclass2(i.ToString()); } } } //which creates public subclass2{ public string name; public subclass2(string inName) { name = in Name; } public subclass2() { // default constructor } } Now when I serialize this thing I'd hope I get back something like ?xml version="1.0" encoding="utf-8"? MainClass xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001... subClass1 blah>blah</blah subclass2 name>0</name /subclass2 subclass2 name>1</name /subclass2 /subClass1 /MainClass Running this in the regular framework I do get that back However running this in the compact framework I get back MainClass xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001... subClass1 blah>blah</blah /subClass1 /MainClass The difference seems to be coming from within the loops but I can't see what Is going wrong there. Is this a known thing? I didn't post my actual code since it's miles long but this is the general idea of what is failing. If I throw in a debug message in the constructor for subClass2 It does fire so it is getting all the way down there it's just not showing up in the XML at the end. Any idea? sorry for the cross post but the XML guys seem to not answer many CF questions. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |