must be marked as Serializable or have a TypeConverter other than ReferenceConverter to be put in vi

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a class that inherits from CollectionBase
The class is marked as Serializable and implements ISerializable. It has a
constructor overload for deserialization also.
CollectionBase holds a class which also is marked as Serializable and
implements ISerializable and also has a constructor overlaod for
deserialization.

I am getting the CollectionClass must be marked as Serializable or have a
TypeConverter other than ReferenceConverter to be put in viewstate.

I have set breakpoints and the GetObjectData is called for both the
CollectionClass and its items. 7 items, 7 calls. However when it exits the
CollectionClass GetObjectData it throws the exception.

I have tried 2 methods of serializating. I just went ahead and
AddValue(this.List); and I have also puyt them in manually 1 item at a time
by myself using a for loop and "Item" + i.ToString(). Both resulted in the
same execution and the same Exception.

Is there something that I am missing that is causing it not to beable to be
saved in the WebPage's ViewState?

Interestingly enough I am having this SAME problem in asp.net 2.0 however it
is capable of serializing the list. Every item that is in the deserialized
list is NULL.


http://www.codeproject.com/aspnet/Strongly_typed_collection.asp
http://www.dotnet247.com/247reference/msgs/45/228617.aspx

I found these samples both of which have similar problems and went ahead I
implemented the same generic TypeConverter that they do, however this did
not solve my woes.

I assume this has to be something pretty obvious that I am missing but for
the life of me I can't seem to find it.
 
Hi,

Safety check - are the items you add to the collection serializable
themselves?
 
Hi Recoil,

Welcome to MSDN newsgroup.
As for the problem on store a custom CollectionBase derived class into
asp.net viewstate, I think it's a specific problem. As far as I knew, for
simple custom types and its collection class, as long as we apply the
[Serializable] attribute to it (don't need to implement ISerialiable
interface) , it can be correctly stored in ViewState.

Have you tried remove the implementation code of the ISerialiable interface
and just using the [serializable] attribute? Also, I think their must
contains some other codelogic in your custom collection class and its
contained item class, maybe that's also the cause. If you feel convenient,
would you try build a simplified version of your item class and collection
class so that we can have a test on our local side?

BTW, the ViewState implementation has much difference between v1.x and
v2.0(whidbey), so I suggest we focus on the 1.x within this issue.

If there is any other findings, please feel free to post here also.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
I had a property that was a Unit and this property is/what was holding
the whole thing up for some reason. I recreated a sample and after
verifying that it worked i went through and began commenting out
certain properties and when I commented out the Unit property it seemed
to work fine.
 
Thanks for your followup Recoil,

Glad that you've found the cause of the problem. Yes,
System.Web.UI.WebControls.Unit structure is not a serializable type into
ViewState , since your custom class (Your Collection class?) contains such
a member property, the runtime serializer will throw the exception you
encountered. We may need to use some other primitive types or our custom
"Unit" class to replace it.

If there are anything else we can help, please feel free to post here.
Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Back
Top