all groups > dotnet xml > march 2005 >
You're in the

dotnet xml

group:

Xml Serialization



Xml Serialization Doug Holland
3/3/2005 10:39:02 AM
dotnet xml: Hey There

I have a couple of collections that I've written that are based upon the
HybridDictionary.

Initially I recieved an exception when attempting to serialize instances of
these collections informing me that I needed to implement an
Add(System.Object) method because the collections inherit from IEnumerable.

"You must implement the Add(System.Object) method on
PrecisionObjects.Collections.Specialized.StringDictionaryEx because it
inherits from IEnumerable."

Once I recieved that exception I thought of implementing the
IXmlSerializable interface directly however it is intended for internal use
within the .NET Framework.

Therefore I decided to initially attempt to implement an appropriate Add()
method as shown here:

public void Add(object value)
{
if(value is DictionaryEntry)
{
DictionaryEntry entry = (DictionaryEntry) value;

if(entry.Key is string && entry.Value is string)
{
this.Add(entry.Key as string, entry.Value as string);
}
}
}

However I now recieve an exception stating "There was an error generating
the XML document", and an inner exception stating:

"The type System.Collections.DictionaryEntry was not expected. Use the
XmlInclude or SoapInclude attributes to specify types that are not known
statically".

I know I could implement IXmlSerializable but would really like to implement
the collection without using classes and interfaces intended for internal use
only as this could cause me problems down the road.

Therefore does anyone have any suggestions on how to resolve this in an
appropriate way?

Regards,

Re: Xml Serialization Barry Kelly
3/7/2005 4:42:15 PM
[quoted text, click to view]

Have you tried using XmlAttributeOverrides?

-- Barry

AddThis Social Bookmark Button