HighTechTalks DotNet Forums  

Serialization in CF problem

Dotnet Framework (Compact Framework) microsoft.public.dotnet.framework.compactframework


Discuss Serialization in CF problem in the Dotnet Framework (Compact Framework) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
jamie
 
Posts: n/a

Default Serialization in CF problem - 03-22-2006 , 04:36 PM






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.



Reply With Quote
  #2  
Old   
Alex Feinman [MVP]
 
Posts: n/a

Default Re: Serialization in CF problem - 03-22-2006 , 07:00 PM






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

Quote:
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.



Reply With Quote
  #3  
Old   
jamie
 
Posts: n/a

Default Re: Serialization in CF problem - 03-22-2006 , 07:49 PM



Hmm I never actually tried running the sample code that I cooked up for an
example. What this suggests is there is actually a difference between my
CF program and the PC version. I really wish it would just die on an error
or something.

Ok thanks I'll keep checking the two to see if I can find anything.

"Alex Feinman [MVP]" <public_news (AT) alexfeinman (DOT) com> wrote

Quote:
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.





Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.