> -----Original Message-----
> From: brian.nantz [mailto:[EMAIL PROTECTED] 
> Sent: Mittwoch, 28. Mai 2003 17:13
> To: [EMAIL PROTECTED]
> 
> First off I'm not sure why XMLSerialize can't handle 
> interfaces.  Isn't this kind of a bad restriction on a 
> language that only has single inheritance and relies heavily 
> on interfaces!????

How would the XmlSerializer deserialize the interface? What class would
you actually deserialize this into?

That said - I find a lot of the "limits" ot the XmlSerializer to be too
much. Seems the creators throught too much about a "round trip
experience", and not enough about "ceating a document from data
objects". If I have no intent to deserialize using the XmlSerializer, I
could actually serialize an interface.

> Here is my question.  I have a barcode class that looks like this:
> 
> public class Barcode : Control, IComponent { }
> 
> When I try to xmlserialize it I get this error:
>  
> System.NotSupportedException: Cannot serialize member 
> System.ComponentModel.Component.Site of type 
> System.ComponentModel.ISite because it is an interface.

Yes :-)

> If I override System.ComponentModel.Component.Site and tell 
> Serialization to ignore it, it doesn't help. In fact if I 
> comment out the IComponent from the class declaration it 
> still compiles but with the same results.

You can not comment it out - I would say that it is defined (publicly) a
level higher up in the class hierarchy, too. Propably the XmlSerializer
chokes there. The Isite is per definition part of the public interface
of your class.

> This tells me that anything that implements IComponent or 
> Inherits from Control can not be xml serialized?  Surely I'm 

This seems to be the case.

> missing something here.  Is there an easy way around this or 
> am I going to have to jump through a bunch of hoops to do a 
> simple xml serialization

Nothing more I can say about it. Well, if you dont get it working, you
can:
(a) create the XML document manually
(b) use the ObjectXPathNavigator from MS and an XSLT transformation to
put the object down as XML

Bt I do hope you get it working.


Regards

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)

Reply via email to