473,734 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Collecti ons;
using System.IO;
using System.Xml.Seri alization;

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)Lis t[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(IntCollecti on XXX) { } // Can be
serialized
public void Add(DataColumn XXX, bool XXXBool) { } // Can be
serialized
// Simply uncommenting any of these methods causes the
XMLSerializatio n 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(VersionNotF oundException XXX) { } // Throws when
serializing
}

class gMain
{
[STAThread]
static void Main(string[] args)
{
XmlSerializer Serializer = new
XmlSerializer(t ypeof(IntCollec tion));
StringWriter XMLStringWriter = new StringWriter();

IntCollection TestCollection = new IntCollection() ;
Serializer.Seri alize(XMLString Writer, TestCollection) ;

Console.WriteLi ne("Serialized TestCollection: ");
Console.WriteLi ne(XMLStringWri ter.ToString()) ;
}
}
}
Nov 11 '05 #1
3 3501
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
3331
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 created a MasterShape class which contains a name, and a 'Shapes' class object, which itself uses the ICollection interface to provide a class which is basically an array of shapes i derive from an abstract base class AbShape, for example i derive...
3
12864
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 accessor on brWAP.clFile because it inherits from ICollectio I must be having a thick day because I dont have a clue what the error message means. (I have written a defaut property called ITEM in the clFile class 'Classes to abstract a FILE entity...
2
3825
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 CollectionBase), in similar fashion as the object models of MS Office. I want to serialize this object graph (with RootObject as the xml document element) without Parent property serialized, this may be done by adding XmlIgnoreAttribute on the...
1
1644
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) equivalent business object(s). I have a custom collection that implements ICollection and IEnumerable. Here is the collection: Imports ERP.BusinessObjects Imports ERP.BusinessObjects.Helpdesk Imports ICTObjects.Collections
5
2366
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 here. But what? What do I want?
0
2011
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 User Private _UserName As String Private _UserCity As String <System.ComponentModel.CategoryAttribute("User Info")> _ Public Property UserName() As String Get
27
1945
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 <Serialized()> attribute on the class and away you go. As Homer would say - "D'Oh" The root of my problem lies in the way VB implements Events and the fact that you can't apply the <NonSerialized> attribute to the little rascals.
3
6695
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 serialize a class containing my new TreeNode, it doesn't seem to save all the properties back up the inheritance chain. The class that is getting serialized has one member to be serialized, a Dictionary<string, List<IOTreeNode>> where IOTreeNode is...
0
5928
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 problem serializing my stuff to XML when it comes to collections. I'm currently using .net2 with generic lists to prevent users putting all sorts of stuff in the arrays (Although im sure i'll be the only user of the classes but not the game, anyway)....
0
8776
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9310
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.