473,657 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlSerializer and nested ArrayLists

Have a class with a public property named "TheFirstProper tyOfArrayListTy pe"
of type ArrayList, property has attribute XmlElement to describe the
contents of the ArrayList, the contents is a public class with attribute
XmlSerializable .
This "second level" class named "SecondClas s" has an attribute of type
XmlSerializable , a public property of type ArrayList, with attribute
XmlElement to describe the contents of the ArrayList, the contents is a
public class (ThirdClass, se below) with attribute XmlSerializable .
This "third level class named "ThirdClass " has three public properties of
simple types (string, string and bool).

Both the SecondClass and the ThirdClass har default constructors and they
inherit from object only

When I try to serialize the property (see first line in this post) with:
:
XmlSerializer serializer = new
XmlSerializer(T heFirstProperty OfArrayListType .GetType());
XmlTextWriter xmlWriter = new XmlTextWriter(" test.xml", Encoding.UTF8);
serializer.Seri alize(xmlWriter , TheFirstPropert yOfArrayListTyp e);
xnlWriter.Close ();

When this is executed an exception of type
'System.Invalid OperationExcept ion' occurred in system.xml.dll
This is thrown in the Serialize method.
Message: Additional information: The type Second was not expected. Use
XmlInclude or SoapInclude to specify types that are not known statically.

Class Second is not created by Reflection so it should be known "statically "
(??)

can anyone tell me what is wrong ? Is it not possible to serialize an
ArrayList containing other ArrayLists containing a class ?
Nov 12 '05 #1
0 2021

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

Similar topics

0
1109
by: Alexandros__ | last post by:
Hello everyone, I am using the Configuration Application block to write an XML configuration file for my application. Most of it is working fine but I have a problem serialising some nested structs that have arraylist fields. What I want to do is to have a ShoppingBasket that will hold any number of Itemstructs and an AllShoppingBaskets that will hold all the ShoppingBaskets. The resulting XML I am after should look like this.
5
5414
by: Stuart Robertson | last post by:
I am trying to find a solution that will allow me to use XmlSerializer to serialize/deserialize a collection of objects where a given object is shared between two or more other objects, and not create duplicate XML representations of the shared object, but instead use IDREFs to refer to the shared object. The XML I'm trying to produce is as follows (where "href" is an IDREF): <?xml version="1.0" encoding="utf-8"?> <MyRootClass...
2
942
by: magister | last post by:
Hello I got this working but it is not how I really want it, basically I have an xml file which has a root of <test> and can be filled with 3 different types of <question> elements with different attributes, all share a base set of 4, one of the question types can have children with <option> elements, this is how the xml looks after serialization.... If you notice there is an extra <SelectionList> around the <option>'s in the final...
1
4614
by: Jamus Sprinson | last post by:
Before I continue, I'm going to begin by saying I'm not by any means an expert- I've been using .NET with C# for about 4 months now, and basically just learning by example and docs. A game project I work on uses Xml serialization to store game objects for loading. One of the techniques we use is to make an array property and use the set block to perform actions on the values after they're loaded from the xml, as in: public string Ids
12
8484
by: SJD | last post by:
I've just read Christoph Schittko's article on XmlSerializer: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp . . . and very informative it is too. I, too, am getting nasty FileNotFound exceptions. I've read, and digested the article, and I think I've found a bug -- it's difficult to track, though it does happen often.
2
7586
by: Steve | last post by:
I'm an XML newb. I'm serializing a class and when I inspect the xml file, all the data is on one line rather than being nested and indented Is that normal? <code> StreamWriter sw = new StreamWriter(m_optionsXmlFilePath, false); XmlSerializer xmlSerializer = new XmlSerializer(typeof(Options)); XmlTextWriter xmlTextWriter = new XmlTextWriter(sw);
5
2387
by: drdave | last post by:
I would like to have ten arraylists created within a loop.. is there a conversion or something I can do to acheive this.. pseudo: Dim counter As Integer = 0 Dim ArrName As ArrayList '******** LOOP OVER THE VALUES ********************
3
3210
by: steve | last post by:
I need to compare the value of a field in a row on an arraylist with the value of a field on a second arraylist I have this bit of code working for arrays but cant get it working for arraylists The secone argument here (1) represents the second field in the row, with arraylists I get a message saying to many arguments. Can I do this with arraylists or do I need to copy the arraylists to arrays? Thanks For q As Integer = 0 To 9 For j...
1
5177
by: JonBeatty | last post by:
I am trying to serialize a class derived from ArrayList called JobQueue that contains an array of objects of the class Job. Using XmlSerializer I can get this to serialize successfully, but I am unable to change the name of the Job element from "anyType" to "Job". It is somewhat of a nit but it does bother me that I'm not understanding the attributes well enough to make this simple change. I have tried numerous options and now I'm just...
0
8312
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,...
1
8504
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
8606
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...
1
6169
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
5632
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2732
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1622
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.