views:

245

answers:

3

Exception Thrown: "System.ComponentModel.ReflectPropertyDescriptor is not marked as Serializable"

Does this mean I missed marking something as serializable myself, or is this something beyond my control?

+1  A: 

Do you have a field of this type in your class. If so, you will have to implement ISerializable yourself -- the automatic implementation requires that all of your fields are marked as Serializable.

Lou Franco
+1  A: 

Can you give more context as to when this happens, and with which serializer? Most serializers have the ability to ignore certain members - NonSerializedAttribute for BinaryFormatter, XmlIgnoreAttribute for XmlSerializer, etc.

Having a PropertyDescriptor instance in your class usually means that your class is acting as a property-bag; in which case you may need to do custom serialization (ISerializable/IXmlSerializable). If the field is there for some other reason, just mark it to be ignored.

This (or similar symptoms) are also very common when you have an event (such as a change notification event / INotifyPropertyChanged) that the UI is hooked into (data binding); in this case, you need to mark the backing field as non-serialized. I don't know about VB, but with C# you can do this with "field-like events" as so:

[field: NonSerialized]
public event EventHandler BarChanged;
Marc Gravell
+1  A: 

It is in your control. Most likely the problem is the same as this: http://www.codeplex.com/SharedCache/Thread/View.aspx?ThreadId=19759

Tom