473,386 Members | 1,754 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,386 software developers and data experts.

XML Serialization Error of Collection

// Can anyone explain the bizarre XML Serialization behavior seen in
the following code.
// It seems that a collection can not be XML Serialized if it contains
an Add() method
// with a single parameter where that parameter is of a type in the
System.Data namespace
// (or a class derived from something in the System.Data namespace).
// Is there any way to prevent this from blowing up?

using System;
using System.Data;
using System.Collections;
using System.IO;
using System.Xml.Serialization;

namespace XMLStub
{
/// <summary>A simple class that holds a collection of
ints.</summary>
public class IntCollection : CollectionBase
{
public int this[int Index]
{
get { return((int)List[Index]); }
}

public void Add(int NewInt)
{
List.Add(NewInt);
}

public void Add(string XXX) { } // Can be
serialized
public void Add(Type XXX) { } // Can be
serialized
public void Add(IntCollection XXX) { } // Can be
serialized
public void Add(DataColumn XXX, bool XXXBool) { } // Can be
serialized
// Simply uncommenting any of these methods causes the
XMLSerialization to fail
// public void Add(DataColumn XXX) { } // Throws when
serializing
// public void Add(DataTable XXX) { } // Throws when
serializing
// public void Add(DataSet XXX) { } // Throws when
serializing
// public void Add(Constraint XXX) { } // Throws when
serializing
// public void Add(VersionNotFoundException XXX) { } // Throws when
serializing
}

class gMain
{
[STAThread]
static void Main(string[] args)
{
XmlSerializer Serializer = new
XmlSerializer(typeof(IntCollection));
StringWriter XMLStringWriter = new StringWriter();

IntCollection TestCollection = new IntCollection();
Serializer.Serialize(XMLStringWriter, TestCollection);

Console.WriteLine("Serialized TestCollection:");
Console.WriteLine(XMLStringWriter.ToString());
}
}
}
Nov 11 '05 #1
3 3473
I tested your code and also found the problem. After checking the
documents, I found there is similair bug reported for XmlSerializer. This
behavior also can be found in VS.NET 2003. The temporary work arround is to
add one more parameter to the function, such as:

public void Add(DataColumn XXX,int i)

Luke

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 11 '05 #2

Do you have any more details on the bug. Such as the ID, or where I can
go to look at its status. Thanks!!!
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 11 '05 #3
There is several bugs which is very similar to this issue, for example,
when serializing in a web service. Currently I am researching to see if
their root cause are same.

Luke

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 11 '05 #4

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

Similar topics

1
by: CodeMonkey | last post by:
Hi, I am trying to use xml serialization to simplify load/save functions in some classes i have created and am hitting a few problems. Any help to either would be most appreciated. I have...
3
by: jamie_m_ | last post by:
I have a custom collection ... clFile that INHERITS from NameObjectCollectionBase the problem is, when I try to create an xmlserializer instance i get an error You must implement a default...
2
by: Snowman | last post by:
Suppose I have a RootObject which holds a collection of other objects. The other objects have a property (Parent) which refers back to the "parent" collection (b.t.w. my collection is based on...
1
by: womber | last post by:
I am getting XML from a dataset that has been populated via a storedprocedure no schemas have been applied nor any relationships. But the correct table names have been given to match the table(s)...
5
by: Arjen | last post by:
Hello, Can somebody help me a little bit? I can't get it to work. Please see my code below... I have placed some comments like "// And whats next?". I'm sure that I have to code something...
0
by: Tom | last post by:
I am having a really annoying issue with serialization and a .NET User Control I am writing. For example, let's say I have a couple of classes in my control - first class is like: Public Class...
27
by: Codemonkey | last post by:
Heya All, Sorry, but I think it's about time for a monkey-ramble. I've just had enough of trying to serialize even simple objects with VB. A simple task you may think - stick the...
3
by: GreyAlien007 | last post by:
I extended the class TreeNode to add some properties of my liking. Anyway, no problems there, I can add my derived TreeNode into TreeNodeCollections and use the properties etc. However, when I...
0
by: crazyone | last post by:
I've got a gaming framework i'm building and i want to save myself the trouble of reading and writting the complete game data to a custom file and load/save it to an XML file but i'm getting...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...

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.