473,395 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Serialize controls

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 hel
Michi
Nov 16 '05 #1
2 2299
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

Nov 16 '05 #2
Thanks a lot
Michi
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
10
by: Dan | last post by:
All I Am Attempting To Serialize An Object To An XML File. Here Is The Code For That public string SaveNewSurvey( MutualSurveyObject mso_TempObject, int i_JobID ) { string s_RootFileName;...
3
by: MAY | last post by:
Hi, I have a problem about serialize the form controls. I wrote a test program to test serialize a from but fail (->An unhandled exception of type...
5
by: objectref | last post by:
Hi to all, let's say i have a form with 2 buttons and 3 textboxes on it. Is there a way to Serialize the form so when i de-Serialize and cast it to a Form, i will get back the original form with...
2
by: Marcel Balcarek | last post by:
Does anyone have an example of serializing an object to a database table?
1
by: js | last post by:
Does anybody knows how to solve the problem? I added attribute to the following classes in Microsoft.Practices.EnterpriseLibrary.Data namespace, but I still get the error. Thanks. ...
0
by: cbonnot | last post by:
Hello, I need to allow a user to dynamically add some controls by using several buttons. After that, I would like to serialize the whole page in order to be able to load the page whenever. ...
4
by: =?Utf-8?B?Qnlyb24=?= | last post by:
When I try to serialize an instance of the LocationCell below (note Building field) I get an error in the reflection attempt. If I remove the _Building field it serializes fine. I tried renaming...
3
by: VingeFaan | last post by:
Hello. Can I serialize a UserControl directly? By that I mean the entire control itself, not by using extra inner classes or specific logic for each usercontrol? I have 50ish usercontrols which I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.