serialize class to the viewstate

C

Craig Buchanan

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
 
A

Anon

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))>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top