Is it possible to serialize (binary) a System.ComponentModel.Container?
Asked
Active
Viewed 419 times
2 Answers
2
No, it is not marked serializable.

Anton
- 5,323
- 1
- 22
- 25
-
I should have selected this a long time ago - it clearly answers my question. I didn't even answer my own question. – IAbstract Feb 06 '10 at 16:32
2
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
- 1,026,079
- 266
- 2,566
- 2,900
-
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. – IAbstract Jan 21 '10 at 16:24
-
1@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 Jan 21 '10 at 16:40
-
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
- and a custom interface making the base component data type quite interchangeable. – IAbstract Jan 22 '10 at 00:43