views:

68

answers:

2

Is it possible to serialize (binary) a System.ComponentModel.Container?

+1  A: 

No, it is not marked serializable.

Anton
I should have selected this a long time ago - it clearly answers my question. I didn't even answer my own question.
dboarman
+2  A: 

What is it you actually want to do here? As has been noted, you can't use BinaryFormatter unless the type is serializable, but you would also need to consider all the things that might be contained in the container. They would also need to be serializable.

You can get around the "must be [Serializable]" issue by not using BinaryFormatter, but most other serializers (for example XmlSerializer) would have a problem with not knowing all the subclasses up-front, and things like non-settable properties.

If you have the right .NET versions, you could also consider things like XamlWriter, which may provide some interesting possibilities.

Marc Gravell
What I'm doing has stemmed from several requirements. The application implements TcpChannels with a common data object. Since it is a MarshalByRefObject, it must be [Serializable]. I know that the CompnonentModel.Container can create a site for it's nested containers and components to communicate - I'm just not experienced with architecting that. I have a feeling that I soon will be. The components and containers are custom classes that will inherit IComponent.
dboarman
@dboarman - I think you need to send a simple data model (DTO or similar) that *represents* the data you want to rehydrate; trying to send anything from ComponentModel isn't going to end well.
Marc Gravell
@Marc: I've gathered that ComponentModel isn't going to really be the answer I'm looking for. I am creating custom 'components' that will be both container and components, building a tree-like structure. So, I will probably create the custom 'component' derived from the generic Node<T> - and a custom interface making the base component data type quite interchangeable.
dboarman