By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,852 Members | 2,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,852 IT Pros & Developers. It's quick & easy.

serialization in compact frame not listing some elements

P: n/a
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?


Mar 22 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi jamie,

I tried to serialize this class to an xml file, and I get what you desired.

<?xml version="1.0" encoding="utf-8" ?>
<Mainclass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<class1>
<blah>blah</blah>
<class2array>
<subclass2>
<name>0</name>
</subclass2>
<subclass2>
<name>1</name>
</subclass2>
</class2array>
</class1>
</Mainclass>

Here is my class file:

public class Mainclass
{

public subclass1 class1;

public Mainclass()
{
class1 = new subclass1();
}
}

//Now that subclass wants to create more classes

public class subclass1 {

public string blah;
public subclass2[] class2array;
public subclass1()
{
blah = "blah";
this.class2array = new subclass2[2];

for (int i =0; i<2; i++)
{
class2array[i] = new subclass2(i.ToString());
}

}
}

//which creates

public class subclass2{

public string name;

public subclass2(string inName)
{
name = inName;
}

public subclass2()
{
// default constructor
}
}

and here is my serialization code:

XmlSerializer ser = new XmlSerializer(typeof(Mainclass));
Mainclass mc = new Mainclass();

ser.Serialize(new XmlTextWriter(@"c:\ser.xml", Encoding.UTF8),
mc);

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Mar 23 '06 #2

P: n/a
Well I finally located the problem. my looping logic was wonky. My main
complaint is that no error was thrown (to be expected I wasn't asking for
anything technically wrong) and there is no good way to debug the
serialization steps, If I could step through it as it was built it should
have saved a bunch of time.
"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:KR**************@TK2MSFTNGXA03.phx.gbl...
Hi jamie,

I tried to serialize this class to an xml file, and I get what you
desired.

<?xml version="1.0" encoding="utf-8" ?>
<Mainclass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<class1>
<blah>blah</blah>
<class2array>
<subclass2>
<name>0</name>
</subclass2>
<subclass2>
<name>1</name>
</subclass2>
</class2array>
</class1>
</Mainclass>

Here is my class file:

public class Mainclass
{

public subclass1 class1;

public Mainclass()
{
class1 = new subclass1();
}
}

//Now that subclass wants to create more classes

public class subclass1 {

public string blah;
public subclass2[] class2array;
public subclass1()
{
blah = "blah";
this.class2array = new subclass2[2];

for (int i =0; i<2; i++)
{
class2array[i] = new subclass2(i.ToString());
}

}
}

//which creates

public class subclass2{

public string name;

public subclass2(string inName)
{
name = inName;
}

public subclass2()
{
// default constructor
}
}

and here is my serialization code:

XmlSerializer ser = new XmlSerializer(typeof(Mainclass));
Mainclass mc = new Mainclass();

ser.Serialize(new XmlTextWriter(@"c:\ser.xml", Encoding.UTF8),
mc);

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Mar 23 '06 #3

P: n/a
Hi Jamie,

It was nice hear that you have had the problem resolved. Yes, we don't have
good ways to debug the serialization process currently. Sorry for the
inconvenience.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Mar 24 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.