0

What des it mean by the following sentence

DependencyObjects are not marked as serializable 

To my knowledge, I can have a class which inherits from DependencyObject...and I can mark it as serializable. Anyway serialize property is not inheritable.

Could someone make me clear. Thanks in advance.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
Relativity
  • 6,690
  • 22
  • 78
  • 128
  • Things missing from this text (cannot call it a question yet) before it becomes a [real question](http://tinyurl.com/so-hints): 1) The platform/OS/programming language you are using 2) What kind of serialization you are doing: text, binary, custom, ... 3) A small and yet complete source code sample of what you are doing (the exact types involved) allowing us to reproduce the problem. Then we can have a base for discussion. – Darin Dimitrov Sep 03 '11 at 17:28
  • there is no issue I am facing..my question is...what does it mean by that sentence ? - DependencyObjects are not marked as serializable – Relativity Sep 03 '11 at 17:32
  • this will very much depend on your answers to `1)` and `2)` to my previous comment. Where did you see this text (in a newspaper (which?), in a blog post (which?), some source code editor in which you type source code (which?))? – Darin Dimitrov Sep 03 '11 at 17:33
  • I saw that comment in http://kentb.blogspot.com/2009/03/view-models-pocos-versus.html....Give me as an answer...only then I can mark your answer and give you points – Relativity Sep 03 '11 at 17:36
  • OK, now we have some context. Let me retag your question. – Darin Dimitrov Sep 03 '11 at 17:38

2 Answers2

3

DependencyObject exists to make use of the entire dependency property system. One side effect of this is that it really doesn't mesh with the approach to serialization taken in .NET.

Serialization, in .NET, serializes fields in a class. However, DependencyObjects don't actually use (instance) fields, but rather registered DependencyProperties, which are stored elsewhere (if at all). As such, they don't serialize properly, even if you mark them [Serializable].

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
3

This means that a class that derives from DependencyObject cannot be serialized with standard serializers. As a workaround you could use XamlReader/XamlWriter as shown in this article.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928