471,610 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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 2576
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.com
"INeedADip" <IN*******@gmail.com> wrote in message
news:OO**************@TK2MSFTNGP12.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.com

"Michael Nemtsev" <ne*****@msn.com> wrote in message
news:9c**************************@msnews.microsoft .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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by smith | last post: by
3 posts views Thread by Cliff Harris | last post: by
2 posts views Thread by MichiSu11 | last post: by
5 posts views Thread by semedao | last post: by
7 posts views Thread by sudhivns | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by MichaelMortimer | last post: by
1 post views Thread by ZEDKYRIE | last post: by

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.