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

XmlSerializing an array of CollectionBase

Hi,

I want to do the following:

I have to XmlSerialize a HashTable, but since it inherits from
IDictionary it cannot be XmlSerialized, and I prefer not to make my
own implementation of IXmlSerializer.

So, I make two arrays, one containing the keys and one containing the
values, and I would like to XmlSerialize these arrays. However, the
values are instances of a class that inherits from CollectionBase.

If I didn't have arrays of objects that inherits from CollectionBase
everything would be fine. The same goes if my objects did not inherit
from CollectionBase. But the combination results in the error:

File or assembly name <random name>.dll, or one of its depencencies,
was not found.

How can I make it work?

My code looks roughly like this:

public class XmlTest
{
public class MyColl : CollectionBase
{
public void Add (string uo) {}

public string this [int index] {get { return "hello";}}
}

[Serializable]
public class SerializeThis
{
[XmlArray]
[XmlArrayItem(Type = typeof(MyColl))]
public MyColl[] myInfo;

public SerializeThis ()
{
}

public SerializeThis (MyColl[] myInfo)
{
this.myInfo = myInfo;
}
}

public void Run (MyColl[] myInfo)
{
StringWriter stringWriter = new StringWriter ();

SerializeThis serializeThis = new SerializeThis();
serializeThis.myInfo = myInfo;

XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
xmlWriter.Formatting = Formatting.Indented;
new XmlSerializer(typeof (SerializeThis)).Serialize (xmlWriter,
serializeThis);
xmlWriter.Flush ();
}
}

Morten
Nov 16 '05 #1
1 3503
Create something like this :

public class Entry
{
public string Key;
public string Value;
}

public class EntryList : CollectionBase
{
public Entry Add(Entry newEntry)
{
return this[List.Add(newEntry)];
}

public Entry this[int index]
{
get{return (Entry) List[index];}
}
}

This shouldn´'t be a problem for a webservice to serialize.

Cu Jens

"Morten Dyndgaard" <mo**************@get2net.dk> schrieb im Newsbeitrag
news:81*************************@posting.google.co m...
Hi,

I want to do the following:

I have to XmlSerialize a HashTable, but since it inherits from
IDictionary it cannot be XmlSerialized, and I prefer not to make my
own implementation of IXmlSerializer.

So, I make two arrays, one containing the keys and one containing the
values, and I would like to XmlSerialize these arrays. However, the
values are instances of a class that inherits from CollectionBase.

If I didn't have arrays of objects that inherits from CollectionBase
everything would be fine. The same goes if my objects did not inherit
from CollectionBase. But the combination results in the error:

File or assembly name <random name>.dll, or one of its depencencies,
was not found.

How can I make it work?

My code looks roughly like this:

public class XmlTest
{
public class MyColl : CollectionBase
{
public void Add (string uo) {}

public string this [int index] {get { return "hello";}}
}

[Serializable]
public class SerializeThis
{
[XmlArray]
[XmlArrayItem(Type = typeof(MyColl))]
public MyColl[] myInfo;

public SerializeThis ()
{
}

public SerializeThis (MyColl[] myInfo)
{
this.myInfo = myInfo;
}
}

public void Run (MyColl[] myInfo)
{
StringWriter stringWriter = new StringWriter ();

SerializeThis serializeThis = new SerializeThis();
serializeThis.myInfo = myInfo;

XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
xmlWriter.Formatting = Formatting.Indented;
new XmlSerializer(typeof (SerializeThis)).Serialize (xmlWriter,
serializeThis);
xmlWriter.Flush ();
}
}

Morten

Nov 16 '05 #2

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

Similar topics

5
by: Steve M | last post by:
I have subclassed CollectionBase. I have also implemented GetEnumerator(). I have tried to set the DataSource of a DataGrid to an instance of my subclass. However, the items in the grid are not...
1
by: Taco | last post by:
The code below will serialize the Catalog object something like: <Catalog> <CatalogTitle>MyCatalog</CatalogTitle> <Books> <Book> <Title>Book1</Title> </Book> <Book> <Title>Book2</Title>...
5
by: Eric Johannsen | last post by:
I have a simple object that inherits from CollectionBase and overrides the Count property: namespace MyTest { public class CollTest : System.Collections.CollectionBase { public override int...
11
by: Vincent Finn | last post by:
Hi, Is there any way of having a strongly typed dynamic array in C#? ArrayList requires you to cast every time you want to access an element object isn't dynamic I have resorted writing a...
0
by: Simon Gregory | last post by:
I'm trying to override the default elementnames in the (seemingly) simple case of serializing an array of GUIDs into XML. Here's the basic code I started with: Dim arrGuids(3) as Guid ...
2
by: Samuel R. Neff | last post by:
What's the advantage of inheriting from CollectionBase as opposed to just implementing IList? It seems that it saves you from having to implement a few properties (Clear, CopyTo, Count,...
1
by: Joe | last post by:
I have a class that is being returned by several WebMethods. Ok - all is good. Now if I have this class implement IEnumerable, the data is no longer serialized. This class does contain a...
3
by: wg | last post by:
I am attempting to create a collection where store and modify multiple entries (i.e. Key, FirstName, LastName, Address, City, Phone, etc). I have attempted to use the CollectionBase but have not...
2
by: Stefan Hoffmann | last post by:
hi, as i'm farely new to C#, i have some problem of creating a shallow copy of a class inherited of CollectionBase. As far as i see, i just need to copy the CollectionBase.List using the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.