473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Xml Serialization doesn't always work

Hi Gurus,

I am having a problem using Xml Serialization - it seems to work only the
second time I try to use it during runtime.

Here's a simplified example (the project is roughly equivalent to folders
and files):

[Serializable]
public class CThingLikeFile
{
private string m_NameProperty;

public CThingLikeFile()
{
m_NameProperty = null;
}

public string NameProperty
{
get { return m_NameProperty; }
set { m_NameProperty = value; }
}
}

[Serializable]
[XmlRootAttribute(IsNullable=false)]
public class CThingLikeFolder
{
private int m_FolderNameProperty;
private CThingLikeFile [] m_TLFiles;

public CThingLikeFolder()
{
m_FolderNameProperty = 0;
m_TLFiles = null;
}

public string FolderNameProperty
{
get { return m_FolderNameProperty; }
set { m_FolderNameProperty = value; }
}

public CThingLikeFile [] TLFiles
{
get { return m_TLFiles; }
set { m_TLFiles = value; }
}
}

[XmlRootAttribute(IsNullable=false)]
public class CThingLikeFileSystem
{
private CThingLikeFolder [] m_TLFolders;

public CThingLikeFileSystem()
{
m_TLFolders = null;
}

public CThingLikeFolderLFiles
{
get { return m_TLFolders; }
set { m_TLFolders = value; }
}
}

And then somewhere....

private void ExportStuff(string FileName)
{
// assume that there is a collection of TLFolders, each of which has TLFiles
CThingLikeFolders [] TheseFolders = GetFolderInfo();

CThingLikeFileSystem TLFileSystem = new CThingLikeFileSystem();
TLFileSystem.TLFolders = TLFolders;

TextWriter tr = new StreamWriter(FileName);
XmlSerializer xs = new XmlSerializer(typeof(CThingLikeFileSystem));
xs.Serialize(tr, TLFileSystem);
tr.Close();
}

On the second time through, and every time thereafter, it correctly will
output the correct XML file. However, on the first run through, the file is
not created, even though I can step through the code and everything looks
correct (the arrays have the correct number of elements, etc.).

Any ideas?

Thanks,
pagates
Nov 17 '05 #1
0 969

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: AP | last post by:
Hello, I'm using .NET 1.1. I have a class that has these two members: public bool FurtherActionsRequired; public bool FurtherActionsRequiredSpecified;
4
by: ron | last post by:
Hi, I have class object that i serialize using the System.Xml.Serialization class. Intermittently the object is not getting serialized correctly, using System.Xml.Serialization classes....
10
by: SStory | last post by:
My app is near completed for the basic feature of version 1.0. I have an extensive object model and I now want to persist my objects using serialization. I have chosen binaryformatter to...
10
by: Uma - Chellasoft | last post by:
Hai, I am new to VB.Net programming, directly doing socket programming. In C, I will be able to map the message arrived in a socket directly to a structure. Is this possible in VB.Net. Can...
5
by: Harold Howe | last post by:
I am having a problem deserializing objects from a library when the following conditions exist: 1- The library is strongly named 2- The serialized file was created with version 1.0 of the...
4
by: Val | last post by:
I have a complex object that I need to serialize. Rather than rely on a standard routine, which is called during the serialization/deserialization, I would like to be able to use my own functions...
4
by: mijalko | last post by:
Hi, I have inherited my class from System.Drawing.Printing.PrintDocument and I wish to serialize this object using XmlSerializer. And I get exception "There was an error reflecting type ...". If I...
11
by: William | last post by:
I'm looking for an example that would show how to serialize a c++ object at it's simplest w/o using any other api's. I have a class that I want to serialize and then pass to my obj-c class so I can...
5
by: =?Utf-8?B?TmF0aGFuIFdpZWdtYW4=?= | last post by:
Hi, We have an app that uses XML serialization throughout. As everyone probably knows, using XML serialization is not always a good idea in a big project...
5
by: RobinS | last post by:
I want to serialize a class that I am using to retain some information the user types into a screen. I have 3 questions. 1) I serialized it as XML to start with. This works, but how do I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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,...

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.