473,544 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IsSerializable

Is there a way to check and see if an object is serializable without just
attempting it and catching the error?
Jan 9 '06 #1
3 2624
INeedADip,

Unfortunately, not easily. If an object is serializable, it will have
the attribute on it (which is really a bit set in the metadata, as opposed
to other attributes). Unfortunately, this doesn't mean that it will
serialize correctly, since the compiler doesn't do a check on all of the
fields of the object being passed in the call (nor can it, really, without
extensive static analysis, which it is beyond the scope of the compiler to
perform).

So in the end, the only option you have is to try and serialize the
instance, and catch the exception.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"INeedADip" <IN*******@gmai l.com> wrote in message
news:OO******** ******@TK2MSFTN GP12.phx.gbl...
Is there a way to check and see if an object is serializable without just
attempting it and catching the error?

Jan 9 '06 #2
Hello Nicholas Paldino [.NET/C# MVP],

And what if to perform check for constrains (like public methods and fields)
dynamically by CodeDom?

N> So in the end, the only option you have is to try and serialize
N> the instance, and catch the exception.
Is there a way to check and see if an object is serializable without
just attempting it and catching the error?

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/members/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Jan 9 '06 #3
Michael,

Well, that's hard to do, when you consider generic types. You basically
have to make sure that each field is serializable. Of course, in order to
do that, you have to make sure that each field in objects referenced in the
class are serializable, and so on, and so on.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Michael Nemtsev" <ne*****@msn.co m> wrote in message
news:9c******** *************** ***@msnews.micr osoft.com...
Hello Nicholas Paldino [.NET/C# MVP],

And what if to perform check for constrains (like public methods and
fields) dynamically by CodeDom?

N> So in the end, the only option you have is to try and serialize
N> the instance, and catch the exception.
Is there a way to check and see if an object is serializable without
just attempting it and catching the error?

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/members/laflour

"At times one remains faithful to a cause only because its opponents do
not cease to be insipid." (c) Friedrich Nietzsche

Jan 9 '06 #4

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

Similar topics

4
1938
by: smith | last post by:
I've been making deep copy clones of objects since my second week or so with ..Net (it took me the first week to realize that shallow copies were usually worthless as "clones"). Normally I call my method "Clone" ... it's just a naming habit I got into with VB5/6 using LSET on UDTs for serializing state and creating copies of objects. The...
3
2309
by: Cliff Harris | last post by:
I have an odd question that I'm hoping someone can help with. I simply (or not simply?) need to enumerate through all of the data types in the .Net framework. I do understand that if this is possible, it will take a long time, and I really don't care :) I need to go through all of the types, look for something within each, and do something...
2
2306
by: MichiSu11 | last post by:
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...
7
2267
by: Lacky | last post by:
Hi frends. I have very interesting problem. It's solution possibly not exist. Take a look. I need to create a method that can serialize any generic C# class (even when it's not implement ISerializable). The idea is simple: 'Store all fields to disk and later restore that class by reading data'. The problem is that most of classes conatins...
1
988
by: andrew | last post by:
I was earlier trying to persist a windows forms control to disk using the binary formatter class. I have devised a workaround, however I have Classes added in as references to my project which still won't serialize properly. I have tested the referenced classes separately as individual projects and added <Serializable(()> Attribute tags...
11
4578
by: DraguVaso | last post by:
Hi, I want to make a small application in VB.NET that relinks all the query's and tables in an Access database that are linked via ODBC to an SQL Server. It must be able to relink all the tables and query's to a given databse, on a given sql server with given login and password. Aybody knows how to do that, or better: has a sample...
2
1663
by: TimJR | last post by:
I am looking for a way to determine in RunTime if a given object is Xml Serializable (short of trying to serialize it to xml and catching the exception). Is this possible? Since an object must have a Default Constructor to be XmlSerializable I have tried something like: Type valueType = aRandomObject.GetType();
5
1211
by: semedao | last post by:
Hi , I have this method to check something.. my question is if changing the order of the "if " will make it faster when the "val" argument is 99% or int or string for example , the IsSerializable is faster or slower then val is string , or val is int...
7
11922
by: sudhivns | last post by:
Hi, I wanted to implement cut/copy/paste operation in C# using ClipBoard class. Eg: Wanted to store the Employee object during cut/copy and perform paste to show in UI. anybody throw lights on how to store the customized class object using ClipBoard class. Thanks,
0
7387
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7643
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7798
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7738
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5316
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4938
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3436
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1862
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
688
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.