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