Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > serialize class to the viewstate

Reply
Thread Tools

serialize class to the viewstate

 
 
Craig Buchanan
Guest
Posts: n/a
 
      01-27-2004
I am trying to serialize a class called Order to the ViewState. Order has
one property called LineItems, which is an ArrayList. The ArrayList holds
instances of a class named LineItem. Bother Order and LineItem are marked
with the <Serializable> attribute.

When I attempt to serialize the class using this code:

Dim xs As XmlSerializer = New XmlSerializer(GetType(Order))

Dim sw As New StringWriter()

xs.Serialize(sw, _Order)

ViewState("LineItems") = sw.ToString()

On the line xs.Serialize(sw, _Order), I get an error that reads:

The type LineItem was not expected. Use the XmlInclude or SoapInclude
attribute to specify types that are not known statically.

What am I missing?

Thanks,

Craig Buchanan


 
Reply With Quote
 
 
 
 
Anon
Guest
Posts: n/a
 
      01-27-2004
You may have to specify what the array list holds with the XmlElement
attribute.

I have a list that holds two different types and I had to do apply the
following to the array list:
<XmlElement(Type:=GetType(StringCriteriaField)),
XmlElement(Type:=GetType(IntegerCriteriaField))>


"Craig Buchanan" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> I am trying to serialize a class called Order to the ViewState. Order has
> one property called LineItems, which is an ArrayList. The ArrayList holds
> instances of a class named LineItem. Bother Order and LineItem are marked
> with the <Serializable> attribute.
>
> When I attempt to serialize the class using this code:
>
> Dim xs As XmlSerializer = New XmlSerializer(GetType(Order))
>
> Dim sw As New StringWriter()
>
> xs.Serialize(sw, _Order)
>
> ViewState("LineItems") = sw.ToString()
>
> On the line xs.Serialize(sw, _Order), I get an error that reads:
>
> The type LineItem was not expected. Use the XmlInclude or SoapInclude
> attribute to specify types that are not known statically.
>
> What am I missing?
>
> Thanks,
>
> Craig Buchanan
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Serialize CommandEventHandler to ViewState? DC ASP .Net 2 04-15-2008 07:37 AM
Can viewstate serialize this class? Ben Amada ASP .Net 7 10-30-2005 07:35 PM
Serialize Style to save ViewState Alex ASP .Net Web Controls 3 03-25-2005 05:15 PM
serialize to SQL Server Blob instead of XML serialize Gordz ASP .Net 3 06-07-2004 07:46 PM
Serialize a class to viewstate? Manit Chanthavong ASP .Net Web Controls 0 01-07-2004 10:38 PM



Advertisments