DevPinoy.org
A Filipino Developers Community

>>> First two to make 3 wins! <<<

Storing business objects in ViewState
A very common exception when storing business objects in ViewState is an HttpException telling you :

"The type [business object] must be marked as Serializable or have a TypeConverter other than ReferenceConverter to be put in viewstate."

But you have marked your business object as serializable with the SerializableAttribute.  ASP.NET Viewstate uses the binary formatter in serializing its contents as part of the the hidden field in pages.  basically it walks through each and every field of your business object and serializes them (You can attach a NonSerializedAttribute for fields that you don't want to be serialized).  If the binaryformatter encounters a problem like one of the fields is not serializable, that means your business object type is not serializable, seems logical but the exception message is not giving you what member is causing the problem.

of course you can walk through all your business objects and mark them as Serializable but the easy way is just to debug it.  Attach an instance of the IDE to the asp.net worker process and configure it to break when an exception is thrown.  After that, open the locals window and you'll see more information on the exception, including the culprit class (the one that is not serializable).

Posted 06-23-2006 6:44 PM by jokiz
Filed under: , ,

Comments

lamia wrote re: Storing business objects in ViewState
on 06-23-2006 3:13 AM
What's the purpose of serializing an object in web apps anyway?
jokiz wrote re: Storing business objects in ViewState
on 06-23-2006 3:25 AM
stateful workarounds on stateless protocol

Copyright DevPinoy 2005-2008