Hello
The property type can be serializable but the value not serializable.
For example when the property type is object (like Tag property), it is
serializable, but it can hold a value of any type since all types inherit
from object. If the value of the Tag property has non serializable type, you
will get this exception.
So you can change the code to something like that.
foreach(PropertyInfo p in pi)
{
object val = p.GetValue(ctl, null);
if(val != null && val.GetType().IsSerializable)
{
AddtoHashtable(p.Name,val);
You can also check for p.CanWrite must be true, because in case you
deserialize, you can't write to readonly property, so (depending on your
application) it might be useless to serialize a ReadOnly property.
Best regards,
Sherif
"MichiSu11" <an*******@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com...
I want to serialize the properties of controls. I write Property Name and
Value to an Hashtable. This hashtable is serialized. So I want to find out
which properties of the control are serializable. I tried following but it
doesn't work. I still get not serializable properties into my hashtable.
Exception of System.Runtime.Serialization.SerializationExceptio n [...] is
not marked as serializable.
PropertyInfo[] pi;
Type t;
t=ctl.GetType();
pi=t.GetProperties (BindingFlags.Public | BindingFlags.Instance);
foreach(PropertyInfo p in pi)
{
if(p.PropertyType.IsSerializable)
{
AddtoHashtable(p.Name,p.GetValue(ctl,null));
Thanks for your help
Michi