473,504 Members | 13,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

serialization in compact frame not listing some elements

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
3 1049
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
3460
by: Charles Crume | last post by:
Hello; My "index.htm" page has 3 frames (content, navigation bar, and logo). I set the "SRC" of the "logo" frame to a blank gif image and then want to change it's contents after the other two...
5
4415
by: Frame | last post by:
I'm looking for tutorials or articles considering HTML Frames and how to handle them with Javascript. E.g. samples how Frames can exchange information, can a Frame instruct other Frame to update...
16
9490
by: Bob Rock | last post by:
Hello, when serializing an array of elements of a class Classname using XmlSerializer.Serialize() I get an XML like the following: <?xml version="1.0"> <ArrayOfClassname> ....... ..........
2
631
by: Michael K. | last post by:
Hello I am trying to serialize some data to an XML-file and most of it works fine. But I do have a problem with to elements. Below is some of the code generated with XSD.exe attached. My...
2
6641
by: Dave Veeneman | last post by:
I'm working on a project where I have to persist data to a file, rather than to a database. Basically, I need to save the state of several classes, each of which will have a couple of dozen...
3
1676
by: S | last post by:
Hi there, Here's a question for ya: I'm serializing something that looks like this: Class Widget --> My base class public ArrayList TextGroups --> An...
8
2451
by: jamie | last post by:
Here's a class I'm working with public class BatchHeader { public string ScaleSite; public string FromScaleDate;
11
16889
by: Rob | last post by:
I know, I know, don't use frames. Well, I'm stuck with these frames and I'm trying to add functionality without a complete redsign. You can look at this as a nostalgic journey. Anyway, I've got...
0
6590
by: bharathreddy | last post by:
Before going to that i want to say few thing on serialization : Serialization is the process of converting an object into a form that can be readily transported. For example, you can serialize an...
0
7213
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7298
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4698
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.