Following on from my previous question I have been working on getting my object model to serialize to XML. But I have now run into a problem (quelle surprise!).
The problem I have is that I have a collection, which is of a abstract base class type, which is populated by the concrete derived types.
I thought it would be fine to just add the XML attributes to all of the classes involved and everything would be peachy. Sadly, thats not the case!
So I have done some digging on Google and I now understand why it's not working. In that the XmlSerializer
is in fact doing some clever reflection in order to serialize objects to/from XML, and since its based on the abstract type, it cannot figure out what the hell it's talking to. Fine.
I did come across this page on CodeProject, which looks like it may well help a lot (yet to read/consume fully), but I thought I would like to bring this problem to the StackOverflow table too, to see if you have any neat hacks/tricks in order to get this up and running in the quickest/lightest way possible.
One thing I should also add is that I DO NOT want to go down the XmlInclude
route. There is simply too much coupling with it, and this area of the system is under heavy development, so the it would be a real maintenance headache!