‘Class’ must be marked as Serializable or have a TypeConverter other than ReferenceConverter to be put in viewstate.

What a PITA. If you want to store an object in the viewstate in ASP.net you need to make sure it is marked as Serializable. Not only that, you need to make sure that every class that it uses is marked as serializable.

There are some scenarios that you don’t have to thought: if you store the objects in Session, you will be ok – unless you try to use out of proc sessions, then you will get the same error for sessions except it will say ‘Class’ must be marked as Serializable or have a TypeConverter other than ReferenceConverter to be put in Session.

If you can, try not to store complex objects in Session/Viewstate and you will save yourself the headache. Or hope that your complex object doesnt use any other classes, then it will be easy for you. :)

Advertisements

2 thoughts on “‘Class’ must be marked as Serializable or have a TypeConverter other than ReferenceConverter to be put in viewstate.”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s