views:

73

answers:

3

Possible Duplicate:
Does adding [Serializable] to the class have any performance implications?

What is the drawback of this attribute? Many of my data objects (DTO) have this attribute because I use to store objects in ViewState. Is there any performance issue regarding this attribute?

A: 

Well, that ties to BinaryFormatter which has a wide range of associated issues, IMO. Not least, it is quite verbose. personally, though - I try never to use viewstate. At all.

It won't make your class slower etc, but I'm not convinced it is a great idea here either.

Marc Gravell
A: 

Apart from the pains of viewstate in and of itself, the [Serializable] attribute can have disadvantages in doing precisely what it is intended to do, when inappropriate.

One case is if a class would need custom serialisation. Say perhaps it has readonly members (and it's a good idea to make members readonly until they need to be otherwise, for similar reasons as it's a good idea to make them private until they need to be otherwise), then custom serialisation will be needed and without it [Serializable] makes a promise that can't be fulfilled.

Another case is if the members contain sensitive data. If you just put [Serializable] on the class without customising the serialisation then while it will work, it will leak that sensitive data.

Jon Hanna